Php 为什么在我的主页上显示草稿
当选择类别时,未发布(草稿)的博客帖子会出现在主页上,但我不想在主页上显示。这是我的WP查询Php 为什么在我的主页上显示草稿,php,wordpress,Php,Wordpress,当选择类别时,未发布(草稿)的博客帖子会出现在主页上,但我不想在主页上显示。这是我的WP查询 <div class="wm_container wm_row wm_blog_listing"> <?php $wm_home_blog_args = array( 'post_type' => 'post', 'posts_per_page' => 4, );
<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
}
?>
在数组中传递Post状态参数
$wm_home_blog_args = array(
'post_type' => 'post',
'posts_per_page' => 4,
'post_status' => 'publish',
);
我希望这对您有用。在数组中传递Post状态参数
$wm_home_blog_args = array(
'post_type' => 'post',
'posts_per_page' => 4,
'post_status' => 'publish',
);
我希望这对你有用
post_状态(字符串/数组)-使用post状态。按帖子状态检索帖子。默认值为'publish'
,但如果用户已登录,则会添加'private'
。默认情况下还包括公共自定义状态。如果查询是在管理上下文(管理区域或AJAX调用)中运行的,那么也会添加受保护的状态。默认情况下,受保护的状态为'future'
,'draft'
和'pending'
post_状态(字符串/数组)-使用post状态。按帖子状态检索帖子。默认值为'publish'
,但如果用户已登录,则会添加'private'
。默认情况下还包括公共自定义状态。如果查询是在管理上下文(管理区域或AJAX调用)中运行的,那么也会添加受保护的状态。默认情况下,受保护的状态为'future'
,'draft'
和'pending'
我也试过,但没用。希望你能尽快给我提出不同的建议我认为您的帖子没有正确更新。请更新一次,然后重试。如果仍然不工作,请在while循环中添加此函数并检查帖子的状态。我也试过了,但没用。希望你能尽快给我提出不同的建议我认为您的帖子没有正确更新。请更新一次,然后重试。如果仍然不工作,请在while循环中添加此函数并检查帖子的状态。这对我很有帮助,但我不知道为什么我的问题仍然存在:(谢谢分享。你是否试图在循环中转储你的
get\u post\u status
,只是为了确保显示的帖子确实是draft
(也许你是从不同的数据库中提取数据,或者是你没有预见到的东西)这对我很有帮助,但我不知道为什么我的问题仍然存在:(谢谢分享。你是否试图在循环中转储你的get\u post\u status
,只是为了确保显示的帖子确实是draft
(也许你是从不同的数据库中提取数据,或者是你没有预见到的东西)