How to show planned and drafts in WordPress categories

Will show to administrators all entries in categories, including those that are planned or in draft.

Before loop:

if (have_posts()) : while (have_posts()) : the_post();

We must add:

// Add scheduled posts and drafts
if (current_user_can(‘activate_plugins’)) {
$ args = [[
‘post_status’ => [[‘publish’, ‘future’, ‘draft’],
];
}

global $ wp_query;
query_posts(
array_merge(
$ wp_query->query,
$ args
)
);

Before the article title, add:

// Display scheduled posts and drafts
if (current_user_can(‘activate_plugins’)) {
$ postStatus = get_post_status();

if ($ postStatus === ‘draft’) {
echo ‘Draft’;
} else if ($ postStatus === ‘future’) {
echo ‘Planned’;
}
}

On the example of the site ploshadka.net (at the time of this writing) it looked like this:

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *