Reputation: 87
Unpublished (draft) blog posts are appearing on the homepage when a category is selected But I don't want to show it on my home page.Here is my WP Query
<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
}
?>
Upvotes: 0
Views: 2432
Reputation: 2542
post_status (string / array) - use post status. Retrieves posts by Post Status. Default value is
'publish'
, but if the user is logged in,'private'
is added. Public custom statuses are also included by default. And if the query is run in an admin context (administration area or AJAX call), protected statuses are added too. By default protected statuses are'future'
,'draft'
and'pending'
.
https://codex.wordpress.org/Class_Reference/WP_Query#Status_Parameters
Upvotes: 3
Reputation: 329
Pass Post Status parameter in array
$wm_home_blog_args = array(
'post_type' => 'post',
'posts_per_page' => 4,
'post_status' => 'publish',
);
I hope this will work for you.
Upvotes: 3