Wha’ts wrong with this PHP If statement that uses the ‘is greater than’ operator?

In this case I want to make the code work only if there are more than 5 replies.

<?php if ( bbp_topic_reply_count() > 5 ) : ?>
    <?php query_posts('gdsr_sort=thumbs&post_type=bbp_reply&posts_per_page=2&post_parent='.$post->ID); ?>
    <?php while ( have_posts() ) : the_post(); ?>
        <h2><?php  the_title(); ?></h2>
        <?php the_content(); ?>
        <?php bbp_reply_author_link( array( 'type' => 'avatar' ) ); ?>
        <?php bbp_reply_author_link( array( 'type' => 'name' ) ); ?>
    <?php endwhile; ?>
    <?php wp_reset_query(); ?>
<?php endif; ?>

The replies are effectively being shown in the code below:

Read More
<h4><?php bbp_topic_reply_count(); ?></h4>

But it seems like its not working in the if statement.

Any suggestions?

Related posts

Leave a Reply

4 comments

  1. Try using:

    if ( bbp_get_topic_reply_count() > 5)
    

    As with many templatey functions in various PHP libraries, there are two variants of this function. One, bbp_topic_reply_count(), automatically echoes the count, rather than returning it. The other, bbp_get_topic_reply_count() actually returns the value to you rather than echoing it.

  2. May I suggest using

    if (bbp_get_topic_reply_count() > 5):
    

    The reason for this is that the function bbp_topic_reply_count() does not return the count value, instead it outputs this value. So when you compare the return value of bbp_topic_reply_count it is null and this produces the following statement

    if (0 > 5) :
    

    Which of course is always false.

  3. bbp_topic_reply_count() isn’t returning the reply count. It is only echoing it. This means you can’t use it as a comparison because the function doesn’t return a number to compare against. I am not familiar with the bbpress functions, but you will have to find an alternative.