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 inWP_Query
class:You can then call it from your theme like this:
see Best Collection of Code for your functions.php file:
if you want this to count all posts, regardless of the type, and status, change
get_posts_by_author_sql()
with"WHERE post_author = '{$user_id}'"
didn’t test that, but it should work…
This should do what you want…