[wp-trac] [WordPress Trac] #40387: WP_Query bug with product post type with search parameter on

WordPress Trac noreply at wordpress.org
Fri Apr 7 11:07:04 UTC 2017


#40387: WP_Query bug with product post type with search parameter on
------------------------------+-----------------------------
 Reporter:  subrataemfluence  |      Owner:
     Type:  defect (bug)      |     Status:  new
 Priority:  normal            |  Milestone:  Awaiting Review
Component:  Query             |    Version:  4.7.3
 Severity:  normal            |   Keywords:
  Focuses:                    |
------------------------------+-----------------------------
 I am not sure if it is a WordPress core bug, but seems like it! I have 5
 different custom post types along with 'product' post type from
 Woocommerce.

 The following query gives (only) product result:

 {{{
 $args = array(
     'post_type' => array('product'),
     'posts_per_page' => 5,
     'post_status' => array('publish', 'future')
 );
 }}}

 Actual query output:

 {{{SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND
 wp_posts.post_type = 'product' AND ((wp_posts.post_status = 'publish' OR
 wp_posts.post_status = 'future')) ORDER BY wp_posts.post_date DESC LIMIT
 0, 5}}}

 But the following query:

 {{{
 $args = array(
     'post_type' => array('product'),
     's' => 'mobile',
     'posts_per_page' => 5,
     'post_status' => array('publish', 'future')
 );
 }}}

 outputs this (even post_type is specified the query is generated to search
 all other post types and surprisingly not product):

 {{{SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND
 (((wp_posts.post_title LIKE '%htc%') OR (wp_posts.post_excerpt LIKE
 '%htc%') OR (wp_posts.post_content LIKE '%htc%'))) AND wp_posts.post_type
 IN ('post', 'travelog', 'hotel-info', 'trips', 'package_tour') AND
 ((wp_posts.post_status = 'publish' OR wp_posts.post_status = 'future'))
 ORDER BY wp_posts.post_title LIKE '%htc%' DESC, wp_posts.post_date DESC
 LIMIT 0, 5}}}

 and brings up results from all other post types and simply ignoring
 product.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/40387>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list