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:
<h4><?php bbp_topic_reply_count(); ?></h4>
But it seems like its not working in the if statement.
Any suggestions?
Try using:
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.May I suggest using
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 statementWhich of course is always false.
I don’t really know the coding conventions of WordPress but I’m sure you don’t have to open and close the php tag
<?php
in every line.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.