0

This is my first time posting a question here, it has been a valuable resource before so I thought maybe someone would be able to answer my question.

It might be a simple solution, but as I said already, I'm a PHP noob. Forgive me.

Here is my code:

    <?php wp_reset_postdata(); // reset the query ?>
<?php $authorposts = get_the_author_posts();
    if ($authorposts < 1) {
    echo " ";
    }
    else { ?>
<div class="single-sidebar"><!--expert_blog start-->
    <div class="single-sidebar-middle">
    <div class="single-sidebar-top">
    <h3>More Posts by <?php the_author();?></h3>
    </div>
    <p><?php echo get_related_author_posts(); ?></p>
    <div class="single-sidebar-bottom">
        <div class="more_blog"><a href="<?php echo get_author_posts_url(get_the_author_meta( 'ID' )); ?>">+ Read more</a></div>
    </div>
    </div>
</div>
<div class="clear"></div>
<?php wp_reset_postdata(); // reset the query ?>

What this is supposed to do: get the number of posts by a particular author (of the post currently being viewed), and output it into a conditional statement saying if it is 1 or less than 1, display nothing. Otherwise, display the titles of each post.

What happens: The divs show up even when there is only one post attirbuted to the author, but nothing shows up in the list (im guessing because there is only one post and you are already viewing it).

Any help would be appreciated, it is late and my brain has melted. Please let me know if anything needs clarification.

Thanks in advance.

1 Answer 1

1

Instead of if ($authorposts < 1) it should be if ($authorposts <= 1)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.