Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

In the codex for WP_Query I see you can query by 'page_id=7' for pages or by 'p=7' for posts... is there a way to get a 'post of any post type' by ID? like 'id=7'—that will get it no matter if it's a page, post or custom post type?

I can only get WP_Query with p=7 to work if I add &post_type=customposttype. Is there a way to get it from the ID regardless of post type?

share|improve this question

1 Answer 1

up vote 10 down vote accepted

'any' should retrieve any type:

$args = array(
'p' => 42, // id of a page, post, or custom type
'post_type' => 'any');
$my_posts = new WP_Query($args);
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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