I'm trying to hide a div in a single page if the current author of the post has only one post. Any ideas on how to achieve this?

<?php hide or don't display if current author has only 1 post ?>
<div>blah blah blah</div>
<?php end ?>
  • 1
    if they have fewer than 1 post, how can you be viewing a single post by that author? – Milo May 30 '16 at 1:37
  • i mean 1 post only then – lee May 30 '16 at 1:46

count_user_posts will give you the number of posts for an author. get_the_author_meta gives you the user's ID. Note that this needs to be in The Loop to get the correct user.

if( 1 < count_user_posts( get_the_author_meta( 'ID' ) , 'post' ) ) {
    echo '<div>blah blah blah</div>';
  • <?php if( 1 < count_user_posts( get_the_author_meta( 'ID' ) , 'post' ) ) { ?><div>blah blah blah</div><?php } ?> works too – lee May 30 '16 at 2:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.