Abdul Hameed
Abdul Hameed

Reputation: 25

How to display "Pending for review post count" on front end

I am writing for a custom spinet to display "Pending Post Count" on front end at the user's page, need to show the pending posts counts for that particular user who is already logged in.

$pending_posts = wp_count_posts()->pending;

using this we can get overall pending post count but i need to display the counts of the particular user who is logged in.

The result should be like

Dear user! "10" Posts are pending for review

Upvotes: 0

Views: 416

Answers (1)

Nick
Nick

Reputation: 356

This will return the number of posts pending:

$number_pending_post = count(get_posts( array('author' => get_current_user_id(), 'posts_per_page' => -1, 'post_type' => 'post', 'post_status' => 'pending')));

You can then echo it:

echo 'Dear user! '.$number_pending_post.' Posts are pending for review';

Watch out for get_current_user_id(), it will return 0 if the user is not logged in. You can wrap this around the condition of is_user_logged_in()

Upvotes: 1

Related Questions