[wp-trac] [WordPress Trac] #18513: Searching with explicit post types unsets page post type

WordPress Trac wp-trac at lists.automattic.com
Wed Aug 24 22:13:08 UTC 2011


#18513: Searching with explicit post types unsets page post type
--------------------------+-----------------------------
 Reporter:  GaryJ         |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Query         |    Version:  3.2.1
 Severity:  normal        |   Keywords:
--------------------------+-----------------------------
 Tested on WP 3.2.1, Twenty Eleven with no plugins, multisite.

 If I explicitly limit a search query via a GET request using an array of
 post_type values, the post_type for page is automatically excluded.

 To reproduce:
  * Do a search on a WP install (perhaps through a modified search form),
 such that the URL is like:
 http://example.com/?post_type[]=post&post_type[]=page&post_type[]=attachment&s=Test
 or
 http://example.com/?post_type[]=post&post_type[]=page&post_type[]=book&s=Test

 That's searching for "Test" on post, page and attachment/book post types.

  * Adding the following to a theme's functions.php:
 {{{
 add_filter( 'pre_get_posts', 'wpcpt_search' );
 /**
  *
  * @param array $query
  */
 function wpcpt_search( $query ) {

         if ( ! $query->is_search )
                 return $query;

         print_r( $query->query_vars );

         return $query;

 }
 }}}

 That spits out (and seemingly confirmed via the values shown in the Debug
 Bar plugin) the following at the beginning:
 {{{
   Array ( [s] => Test [post_type] => Array ( [0] => post [2] => attachment
 )
 }}}
 and only returns results for posts and attachments (or books). The fact
 that key 1 is missing makes me think that page was in the array at some
 point, but it's been unset, but I can't see where, or why, this might be
 done.

 (When no post_type is set, giving a post_type of 'any', which in turn
 gives all of the non-excluded_from_search post types, then page is one of
 the array values, and the search results correctly include pages.)

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/18513>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list