Opened 16 years ago
Closed 16 years ago
#10885 closed defect (bug) (fixed)
Custom post types show up in search
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 2.9 | Priority: | normal |
| Severity: | normal | Version: | 2.8.4 |
| Component: | Query | Keywords: | |
| Focuses: | Cc: |
Description (last modified by )
Custom post types can show up in search results. Searches set the post_type to "any". "any" queries pull in all post types except "revision", which is special cased. We need a means for plugins to exclude their type from searches. Either they can set a custom post_status to avoid getting in the search query as a matter of policy or provide API for registering the type and excluding it more formally.
Attachments (4)
Change History (14)
#3
@
16 years ago
Thinking we add register_post_type() and exclude all custom post types from search by default with ability to opt-in.
That sounds the best to me, Just have the initial list array('post', 'page', 'attachment') and let us filter it.. or.. Just let us filter the list which should be excluded..
#4
@
16 years ago
I considered simply adding an array of post types to exclude that can be filtered, but since other situations have come up where having a list of registered post types was needed I decide to go ahead and register them like we do with taxonomies.
#5
@
16 years ago
Sounds fair enough to me.
Could we add a few GET api's instead of using the globals directly? Much like the taxonomies..
get_post_types()
Could even simplify things a little for calling functions by doing an array_intersect, for example, This'd only return items matching...
get_post_types( array('exclude_from_search' => false) );
Would save other code blocks having to iterate over and check for conditionals themselves.. Just a thought :)
#7
@
16 years ago
Patch adds get_post_types(). Should it return a list of post type names or objects?
Thinking we add register_post_type() and exclude all custom post types from search by default with ability to opt-in.