即使接触wordpress很久,也很难全部熟悉wordpress众多内置函数。
遇到一个问题时,我们总会在自己已知的世界里搜寻答案,譬如这个问题:
如何统计当前用户已发布的日志数量?
首先想到可以用WP_Query来实现,如:
$authorid = get_current_user_id();
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'author' => $authorid,
);
$query = new WP_Query($args);
$count = $query->found_posts;
wp_reset_query();
return $count;
虽然可以实现同等效果,但其实wordpress针对该问题,已经有了内置函数:count_user_posts
要解决这个问题,一句即可:
$user_post_count = count_user_posts( get_current_user_id() , 'post' );
怎么样,很简便吧?!
还得多继续努力学习哈~~
Really your tutorial is professional and i increase skill to seen the post. Thanks a lot for sharing.
Your chain tutorial create me a experts wordpress user. Now wordpress easy to me. Thanks for tech me.