WP_Query by just the id?
In the codex for
WP_QueryI see you can query by
page_id=7for pages or by
p=7for posts. Is there a way to get a post of any post type by ID? Like
id=7that will get it no matter if it's a page, post or custom post type?
I can only get
p=7to work if I add
&post_type=customposttype. Is there a way to get it from the ID regardless of the post type?
anyshould retrieve any type:
$args = array( 'p' => 42, // ID of a page, post, or custom type 'post_type' => 'any' ); $my_posts = new WP_Query($args);
Note the description of
anyin the documentation:
'any' - retrieves any type except revisions and types with 'exclude_from_search' set to true.
For more information, have a look at the documentation of WP_Query.