[wp-trac] [WordPress Trac] #55004: WP_Query IN operator has limits

WordPress Trac noreply at wordpress.org
Tue Feb 1 07:55:25 UTC 2022


#55004: WP_Query IN operator has limits
---------------------------+------------------------------
 Reporter:  hajakutbudeen  |       Owner:  (none)
     Type:  defect (bug)   |      Status:  assigned
 Priority:  normal         |   Milestone:  Awaiting Review
Component:  Query          |     Version:
 Severity:  normal         |  Resolution:
 Keywords:  close          |     Focuses:
---------------------------+------------------------------

Comment (by hajakutbudeen):

 Hey @peterwilsoncc,

 Thanks for your replay. Really appreciated.

 Example Shortcode:
 $id_list = array(2321,2232,3333......19517);
 [products ids='".implode(',',$id_list)."' columns="3" limit="9"
 pagination="true" prdctfltr="yes"]

 STAGE 1 - Create args pass into WP_QUERY:
 file name:       woocommerce/include/shotcodes/class-wc-shortcode-
 products.php
 function name:   get_query_results()
 code:            $query = new WP_Query( $this->query_args );

 STAGE 2 - Create SQL query pass into $wpdb->get_col:
 file name:       wp-includes/class-wp-query.php
 function name:   get_posts()
 code:            $this->posts = $wpdb->get_col( $this->request );

 Example $this->request:
 "SELECT SQL_CALC_FOUND_ROWS  wp_posts.ID FROM wp_posts  LEFT JOIN
 wp_wc_product_meta_lookup wc_product_meta_lookup ON wp_posts.ID =
 wc_product_meta_lookup.product_id  WHERE 1=1  AND wp_posts.ID IN
 (...............................LIST OF IDS.............................)
 AND ( \n  wp_posts.ID NOT IN (\n\t\t\t\tSELECT object_id\n\t\t\t\tFROM
 wp_term_relationships\n\t\t\t\tWHERE term_taxonomy_id IN (9)\n\t\t\t) \n
 AND \n  wp_posts.ID NOT IN (\n\t\t\t\tSELECT object_id\n\t\t\t\tFROM
 wp_term_relationships\n\t\t\t\tWHERE term_taxonomy_id IN (7)\n\t\t\t) \n
 AND \n  wp_posts.ID NOT IN (\n\t\t\t\tSELECT object_id\n\t\t\t\tFROM
 wp_term_relationships\n\t\t\t\tWHERE term_taxonomy_id IN (9)\n\t\t\t) \n
 AND \n  wp_posts.ID NOT IN (\n\t\t\t\tSELECT object_id\n\t\t\t\tFROM
 wp_term_relationships\n\t\t\t\tWHERE term_taxonomy_id IN (7)\n\t\t\t)\n)
 AND wp_posts.post_type = 'product' AND ((wp_posts.post_status =
 'publish')) GROUP BY wp_posts.ID ORDER BY
 wc_product_meta_lookup.min_price ASC, wc_product_meta_lookup.product_id
 ASC  LIMIT 0, 12"

 IDS count:
 i paste all ids into MS-Word check character count
 [[Image(https://ibb.co/yNVdSmn)]]

 If i remove around 3000+ ids from id list then it work. I checked already
 there's no duplicate ids in that list. I dig into that then i found this,
 https://stackoverflow.com/questions/4275640/mysql-in-condition-limit

 Please advise, Thank you

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


More information about the wp-trac mailing list