0

How do I use get_posts to filter against a single post id? (I don't want to use get_post because am using this in another function that could take other parameters and should return an array). The following methods are not working:

get_posts(array(
    'ID' => 12345,
));

get_posts(array(
    'p' => 12345,
));

get_posts(array(
    'post' => 12345,
));

get_posts(array(
    'post__in' => array(12345),
));

1 Answer 1

1

Nevermind, all of these methods work if I add the post_type parameter to the query:

get_posts(array(
    'ID' => 12345,
    'post_type' => array('any'),
));

get_posts(array(
    'p' => 12345,
    'post_type' => array('any'),
));

get_posts(array(
    'post' => 12345,
    'post_type' => array('any'),
));

get_posts(array(
    'post__in' => array(12345),
    'post_type' => array('any'),
));

This is a really stupid design decision; any post type should be assumed if the parameter is omitted.

Your Answer

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

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