Forums

[resolved] Conditional on author with no posts in cat... (4 posts)

  1. theApe
    Member
    Posted 2 years ago #

    How would I make a conditional statement for an authors specific content to show one thing or another depending on whether that certain author has posted to a specific category. For example...

    In the post meta of any post written by 'Jane'. The statement needs to be conditional on whether she has ever posted to a certain category.

    if
    Post count 1+ in cat X ->[Jane has at some point in time posted to X category]
    else
    Post count 0 in cat X ->[Jane has never posted to X category]
    end

    Any help would be appreciated I've not be able to find a conditional tag for whether a category has posts or not in the codex.

  2. theApe
    Member
    Posted 2 years ago #

    Alternatively, how can I call an authors ID in author archive if they have no posts.

  3. MichaelH
    Volunteer
    Posted 2 years ago #

    In a loop you could use:

    <?php
    $userposts = get_posts('cat=3&showposts=-1&author='.$post->post_author);
    $count=count($userposts);
    if ($count) {
    echo '<p>author has this number of posts in category 3: ' .$count . '</p>';
    } else {
    echo '<p>author has no posts in category 3</p>';
    }
    ?>
  4. theApe
    Member
    Posted 2 years ago #

    $userposts = get_posts('cat=3&showposts=-1&author='.$post->post_author);
    $count=count($userposts);
    if ($count)

    Thank you! That was exactly what I needed!

Topic Closed

This topic has been closed to new replies.

About this Topic