查询帖子、迭代结果和处理帖子状态听起来非常简单。。只需确保添加\'post_status\' => \'any\'
添加到查询参数,以便在已发布的旁边包含更多状态:
$args = array(
\'author\' => 1, // user ID here
\'posts_per_page\' => -1, // retrieve all
\'post_type\' => \'post\', // post type (change to your PT)
\'post_status\' => \'any\' // any status
);
$posts = get_posts( $args );
$drafts = $pendings = $published = array();
if ( ! empty( $posts ) ) :;
foreach ( $posts as $post ) {
switch ( $post->post_status ) {
case \'draft\':
$drafts[] = $post;
break;
case \'pending\':
$pendings[] = $post;
break;
case \'published\':
$published[] = $post;
break;
default:
break;
}
}
endif;
echo var_dump( \'drafts\', $drafts, \'pending\', $pendings, \'published\', $published ); // or print_r
希望这有帮助。
这将用于规则。如果用户在某个帖子类型上的帖子数量大于或等于X,他们将看到自定义文本。
用法示例:if ( count( $drafts ) >= (int) X ) { # Hey!! }