[wp-trac] [WordPress Trac] #17592: 'exclude_from_search' excludes from non-search queries

WordPress Trac wp-trac at lists.automattic.com
Fri Dec 16 14:16:56 UTC 2011


#17592: 'exclude_from_search' excludes from non-search queries
--------------------------+-----------------------------
 Reporter:  danblaker     |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Future Release
Component:  Query         |     Version:  3.1.2
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |
--------------------------+-----------------------------
Changes (by netweblogic):

 * cc: msykes@… (added)


Comment:

 Whilst working on my plugin, I had to make a workaround. This seems to
 work:

 {{{
 #!php
 function my_cp_parse_query( ){
         global $wp_query;
         //Search Query Filtering
         if( !empty($wp_query->query_vars['s']) && $include_in_search ){
                 $wp_query->query_vars['post_type'] = array_diff(
 get_post_types(array('exclude_from_search' => false)),
 array('my_custom_post'));
         }
 }
 add_action('parse_query','my_cp_parse_query');
 }}}

 It just checks to see if a search is being made, if so, get all the
 searchable post types and remove yours from the list, supplying that array
 to post_type query var. Hope that helps someone!

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/17592#comment:9>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list