当选择某个类别时,未发布的(草稿)博客帖子会出现在主页上但是我不想在我的主页上显示它。这是我的WP查询
<div class="wm_container wm_row wm_blog_listing">
<?php
$wm_home_blog_args = array(
'post_type' => 'post',
'posts_per_page' => 4,
);
$wm_home_blog_qry = new WP_Query($wm_home_blog_args);
if ($wm_home_blog_qry->have_posts()) {
while ($wm_home_blog_qry->have_posts()) {
$wm_home_blog_qry->the_post();
$wm_categories = get_the_category($post->ID);
$wm_home_term_ID = $wm_categories[0]->term_id;
$wm_home_blog_bg = get_term_meta($wm_home_term_ID, 'wm_term_color', true);
?>
<article class="wm_col wm_col_3 wm_blog_item"
style="background-color: <?php echo $wm_home_blog_bg; ?>">
<?php
if (has_post_thumbnail()) {
?>
<a class="wm_post_thumbnail_wrapper" href="<?php the_permalink() ?>">
<?php
the_post_thumbnail('wm_recent_issue_cat');
?>
<span class="wm_image_overlay">Preview</span>
</a>
<?php
} else {
?>
<a class="wm_post_thumbnail_wrapper" href="<?php the_permalink() ?>">
<img src="http://placehold.it/255x135?text=No+Image">
<span class="wm_image_overlay">Preview</span>
</a>
<?php
}
?>
答案 0 :(得分:2)
在数组中传递Post Status参数
$wm_home_blog_args = array(
'post_type' => 'post',
'posts_per_page' => 4,
'post_status' => 'publish',
);
我希望这对你有用。
答案 1 :(得分:0)
post_status ( string / array ) - 使用帖子状态。按帖子状态检索帖子。默认值为
'publish'
,但如果用户已登录,则会添加'private'
。默认情况下还包括公共自定义状态。如果查询在管理上下文(管理区域或AJAX调用)中运行,则也会添加受保护的状态。默认情况下,受保护状态为'future'
,'draft'
和'pending'
。
https://codex.wordpress.org/Class_Reference/WP_Query#Status_Parameters