admin管理员组文章数量:1026154
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 the post type?
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 the post type?
1 Answer
Reset to default 98any
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);
Note the description of any
in 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.
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 the post type?
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 the post type?
1 Answer
Reset to default 98any
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);
Note the description of any
in 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.
本文标签: wp queryWPQuery by just the id
版权声明:本文标题:wp query - WP_Query by just the id? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745623101a2159697.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论