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

WordPress Trac noreply at wordpress.org
Mon Apr 10 10:48:39 UTC 2017


#40387: WP_Query bug with product post type with search parameter on
------------------------------+-----------------------
 Reporter:  subrataemfluence  |       Owner:
     Type:  defect (bug)      |      Status:  reopened
 Priority:  normal            |   Milestone:
Component:  Query             |     Version:  4.7.3
 Severity:  normal            |  Resolution:
 Keywords:                    |     Focuses:
------------------------------+-----------------------
Changes (by subrataemfluence):

 * status:  closed => reopened
 * resolution:  invalid =>


Comment:

 Hi @boonebgorges, thank you for looking into my issue. As per your advise
 I disabled (deactivated) all my plugins. Then created a template page
 where I put the following code first:

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

 $q = new WP_Query($args);
 echo $q->request;
 }}}

 Here is the output:

 {{{#!php
 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
 }}}

 which is exactly what I want!

 Now I added the search query part in `$args` i.e


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

 $q = new WP_Query($args);
 echo $q->request;
 }}}

 and the output is:

 {{{#!php
 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
 }}}

 which shows the problem is still there. There is no `product` post type
 included in query, rather all other post types are available which I never
 asked WordPress to include through my above query.

 I have ALL plugins deactivated, ready made as well as those I built for
 this site.

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


More information about the wp-trac mailing list