Skip to:
Content
Pages
Categories
Search
Top
Bottom

Get count of the all topics with no replies


  • Radzio125
    Participant

    @radzio125

    Hi, how to get count of the all topics with no replies? I want to create something like this:

    $count = ????
    if ( $count != 0 ) {
    echo '<a href=".../no-replies/">Topics with no replies<span class="count">'. $count .'</span></a>';
    }

    Is there a easy way to do this? I will be grateful for help.

Viewing 2 replies - 1 through 2 (of 2 total)

  • Robin W
    Moderator

    @robin-w

    I think this does it

    $count = rew_count_no_replies () ;
    
    function rew_count_no_replies () {
    	global $wpdb;
    	$type = bbp_get_topic_post_type() ;
    	$count = (int) $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts, $wpdb->postmeta	
    	WHERE $wpdb->posts.post_type = '$type'
    	AND ( $wpdb->posts.post_status = 'publish' OR $wpdb->posts.post_status = 'private' )
    	AND $wpdb->posts.ID = $wpdb->postmeta.post_id 
        AND $wpdb->postmeta.meta_key = '_bbp_reply_count'
        AND $wpdb->postmeta.meta_value = 0 ");
    	return $count ;
    }

    Radzio125
    Participant

    @radzio125

    Yes! It works! Thank you very much! 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar