3

I did quite a bit of research but can't figure why this wouldn't work for me?

echo print_r($rel); // Array ( [0] => 63 [1] => 87 )

$args = array(
    'post_type' => array( 'post' ),
    'orderby' => 'ASC',
    'post_in' => $rel
);

$loop = new WP_Query( $args );

I don't get any posts returned? Any ideas how to only get the posts with the ids in the array?

7

You have to use post__in (double underscore) argument, instead of post_in:

echo print_r($rel); // Array ( [0] => 63 [1] => 87 )

$args = array(
    'post_type' => array( 'post' ),
    'orderby' => 'ASC',
    'post__in' => $rel
);

$loop = new WP_Query( $args );

If you are unsure why an argument is not working, copy it's key name from manual and past it into you snippet.

  • @mathiregister u r welcome! :) – Eugene Manuilov Feb 20 '13 at 12:11
  • The above snippet throws an error (in wordpress 4.9.5 )and you have to use 'post__in' => array($rel) – jeh Feb 26 at 17:05

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.