5

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?

1 Answer 1

13

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.

2
  • @mathiregister u r welcome! :) Commented Feb 20, 2013 at 12:11
  • The above snippet throws an error (in wordpress 4.9.5 )and you have to use 'post__in' => array($rel) Commented Feb 26, 2019 at 17:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.