0

I am using the following code to generate a specific list of posts with WP_Query

$args = array (
    'post__in'   => $cookie_array,
    'post_type'  => 'tyre',
    'post_status'    => 'publish',
    'posts_per_page' => '100',
);

$cookie_array is an array I generate based on some values in a cookie (post id's). The problem is that for some reason the WP_Query won't display the post that corresponds to the last value in the array. For example if the array consists of 1,2,3 then my WP_Query only gets the posts with the id's 1 and 2.

I've printed out the values of the array, right before I call the argument list shown above and there's definitely 1 more value listed than WP_Query is getting.

Any ideas what's going on?

Edit

As per request the result of var_dump($cookie_array) - to confirm only 3 items are shown through my WP_Query when the array is set as below:

array(4) { [0]=> string(5) "15829" [1]=> string(5) "22728" [2]=> string(5) "22734" [3]=> string(5) "22725" } 

var_dump($getposts->request) outputs:

 string(230) "SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.ID IN (15829,22728,22734,22725) AND wp_posts.post_type = 'tyre' AND ((wp_posts.post_status = 'publish')) ORDER BY wp_posts.post_date DESC LIMIT 0, 100"
  • Can you show here your var_dump($cookie_array); result? – Bindiya Patoliya May 7 '14 at 7:49
  • Added to original post :) – Kev May 7 '14 at 7:58
  • What does var_dump($query->request) say? (Where $query is your instance of WP_Query) – David May 7 '14 at 8:00
  • Updated OP again with var_dump($getposts->request) – Kev May 7 '14 at 8:15
  • 1
    And you get results when you query without the post__in part? And you're sure all of those posts are published posts of type 'tyre'? – Tom J Nowell May 7 '14 at 9:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.