解决方案很简单,请删除if
检查您的问题并添加post_status
参数到get_posts
.
例如:
$args = [
\'post_status\' => \'publish\',
];
$only_published_posts = get_posts( $args );
同样,我们可以传递我们想要的状态数组,例如。
$args = [
\'post_status\' => [ \'publish\', \'pending\' ],
];
$only_published_and_pending_posts = get_posts( $args );
或除已发布帖子外的所有内容:
$args = [
\'post_status\' => [ \'future\', \'draft\', \'pending\' ],
];
$not_published = get_posts( $args );
或私人职位:
$args = [
\'post_status\' => [ \'private\' ],
];
$private_posts = get_posts( $args );
或所有post状态,包括修订和自动草稿:
$args = [
\'post_status\' => \'any\',
];
$all_posts = get_posts( $args );
There are a limited number of post statuses that come with core, and they\'re hard coded, so you can just list the ones you want, and ommit the ones you don\'t.
更多信息,请访问:
https://developer.wordpress.org/reference/classes/wp_query/#status-parameters请注意,虽然这是规范的标准WordPress方法,但插件可能会使用自定义的post状态,如果构建得不好,则会完全忽略状态。在这些情况下,您需要联系他们的开发支持路线