WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 25 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


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.