2016-11-11 28 views
0

未公布(草案)的博客文章都出现在网页上是我的WP查询为什么文章草稿显示在我的主页时,选择一个类别,但我不希望显示它在我家page.Here

<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 
        } 
        ?> 
在阵列

$wm_home_blog_args = array(
      'post_type' => 'post', 
      'posts_per_page' => 4, 
      'post_status' => 'publish', 
     ); 

回答

0

post_status串/阵列) - 使用后的状态。按发布状态检索帖子。默认值是'publish',但如果用户已登录,加入'private'。公共自定义状态也默认包含在内。如果查询是在管理方面(管理区或AJAX调用)运行,保护的状态太补充说。默认情况下,受保护的状态是'future''draft''pending'

https://codex.wordpress.org/Class_Reference/WP_Query#Status_Parameters

+0

它非常有帮助我,但不知道为什么,我的问题仍然是:( – Talha

+0

谢谢分享。 – Talha

+0

你想甩了你'get_post_status'内环路,只是为了确保显示的帖子是'draft'确实(或许你是从不同的DB或拉的东西,你的数据没有预见到) – arhak

2

通行证后状态参数我希望这会为你工作。

+0

我也尝试过,但不起作用。希望你能尽快提出不同的方法。 ;) – Talha

+0

我觉得您的文章没有更新properly.update一次,然后尝试 –

+0

如果仍无法正常工作,在while循环中添加此功能,并检查后的状态。 https://codex.wordpress.org/Function_Reference/get_post_status –

相关问题