下面是一个代码示例,注释中有解释:
// First a check whether the use is logged in or not:
if ( is_user_logged_in() ) {
// The user is logged, retrieve the user id
$user_ID = get_current_user_id();
// Now we have got the user\'s id, we can pass it to the function \'count_user_posts\':
echo \'Number of posts published by user: \' . count_user_posts( $user_ID );
} else {
// The user is not logged in
}