I am trying to display different things to new users that have not created a post versus users who have created a post.
I tried this, but it did not work for custom post types (only normal posts) and it does not account for drafts or pending posts:
<?php if (count_user_posts(1)>=1) { blah blah blah } else {Welcome, blah blah blah }; ?>
Hi @Carson:
A simple function to address what you are asking for might be the function yoursite_user_has_posts()
which leverages the built in WP_Query
class:
function yoursite_user_has_posts($user_id) {
$result = new WP_Query(array(
'author'=>$user_id,
'post_type'=>'any',
'post_status'=>'publish',
'posts_per_page'=>1,
));
return (count($result->posts)!=0);
}
You can then call it from your theme like this:
<?php
$user = wp_get_current_user();
if ($user->ID)
if (yoursite_user_has_posts($user->ID))
echo 'Thank you for writing!';
else
echo 'Get Writing!';
?>