admin管理员组文章数量:1313185
I'm trying to select all rows from the database regardless of post type, however when suppressing post_type WP_Query only gets rows with post_type = "post"
is there a way to suppress the post_type filter (or select all post types)?
// This just selects post_type = "posts"
$args = array(
'post_status' => 'publish',
'posts_per_page' => -1,
'ignore_sticky_posts' => true,
);
$qry = new WP_Query( $args );
I'm trying to select all rows from the database regardless of post type, however when suppressing post_type WP_Query only gets rows with post_type = "post"
is there a way to suppress the post_type filter (or select all post types)?
// This just selects post_type = "posts"
$args = array(
'post_status' => 'publish',
'posts_per_page' => -1,
'ignore_sticky_posts' => true,
);
$qry = new WP_Query( $args );
Share
Improve this question
asked Mar 10, 2014 at 15:38
Lisandro VaccaroLisandro Vaccaro
9954 gold badges12 silver badges28 bronze badges
1 Answer
Reset to default 1By default-- that is, unlss told otherwise-- WP_Query
will search the post
post type. You may supply 'post_type' => 'any'
to retrieve all post types, but be aware that things like attachments are post types. For example...
$args = array(
'post_status' => 'publish',
'posts_per_page' => -1,
'ignore_sticky_posts' => true,
'post_type' => 'any'
);
$qry = new WP_Query( $args );
var_dump($qry->request);
Post types set as not searchable, such as the menu post type (which has no business being a post type at all IMHO), will be ignored. If you need those odd-ball post types, you will need to list them. get_post_types()
should help with that.
$args = array(
'post_status' => 'publish',
'posts_per_page' => -1,
'ignore_sticky_posts' => true,
'post_type' => get_post_types(),
);
$qry = new WP_Query( $args );
本文标签: wp querySelect posts with any posttype from database
版权声明:本文标题:wp query - Select posts with any post_type from database? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741921370a2405024.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论