【问题标题】:How to display "Pending for review post count" on front end如何在前端显示“待审核帖子计数”
【发布时间】:2019-04-15 22:45:55
【问题描述】:

我正在编写一个自定义spinet,以在用户页面的前端显示“待处理的帖子计数”,需要显示已登录的特定用户的待处理帖子计数。

$pending_posts = wp_count_posts()->pending;

使用这个我们可以获得总的待处理帖子计数,但我需要显示登录的特定用户的计数。

结果应该是这样的

Dear user! "10" Posts are pending for review

【问题讨论】:

  • 你有没有尝试过?展示你目前拥有的东西。

标签: php wordpress


【解决方案1】:

这将返回待处理的帖子数:

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

然后你可以回显它:

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

注意get_current_user_id(),如果用户没有登录,它会返回0。你可以把它包裹在is_user_logged_in()的条件上

【讨论】:

  • 太棒了!它工作正常,感谢尼克的支持:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多