return FALSE; $r = well_tag_thread__update(array('id' => $id), $update); return $r; } function well_tag_thread_find($tagid, $page, $pagesize) { $arr = well_tag_thread__find(array('tagid' => $tagid), array('id' => -1), $page, $pagesize); return $arr; } function well_tag_thread_find_by_tid($tid, $page, $pagesize) { $arr = well_tag_thread__find(array('tid' => $tid), array(), $page, $pagesize); return $arr; } ?>wp query - Select posts with any post_type from database?
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

wp query - Select posts with any post_type from database?

programmeradmin0浏览0评论

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
Add a comment  | 

1 Answer 1

Reset to default 1

By 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 );
发布评论

评论列表(0)

  1. 暂无评论