Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to get the number of replies to a specified replyID


  • eigodeasobo
    Participant

    @eigodeasobo

    Is there a function to specify replyID and get the number of replies to it?

    For example, if you have the following HTML, I would like to know about functions that can write “<?php xxx(100) ?>” and get “2”.

    <div id="bbpress-forums">
      <ul id="topic-1-replies" class="forums bbp-replies">
        <li>
          <div id="post-100">
            <p>Hello!</p>
          </div>
        <li>
        <ul class="bbp-threaded-replies">
          <li>
            <div id="post-101">
              <p>Hi!</p>
            </div>
          <li>
          <li>
            <div id="post-102">
              <p>Cheers!</p>
            </div>
          <li>
        </ul>
      </ul>
    </div>
Viewing 7 replies - 1 through 7 (of 7 total)

  • Robin W
    Moderator

    @robin-w

    $topic_id = 100 ;
    $ count = bbp_get_topic_reply_count( $topic_id) ;
    echo $count ;

    or shorter

    $topic_id = 100 ;
    echo bbp_topic_reply_count( $topic_id ) ;

    eigodeasobo
    Participant

    @eigodeasobo

    It is a code that specifies the topic ID and obtains the number of replies.

    What I want to know is a code that specifies the reply ID and obtains the reply number.


    Robin W
    Moderator

    @robin-w

    so a threaded reply – yes ?


    eigodeasobo
    Participant

    @eigodeasobo

    Yes, I’d like to specify a reply to a topic and get the number of replies to it.

    I am glad if there is a function like xxx below.

    <?php
    $topic_id = 1 ;
    echo bbp_topic_reply_count( $topic_id ) ;
    // 3
    ?>
    
    <?php xxx(100) ;
    // 2
    ?>
    
    <?php xxx(101) ;
    // 0
    ?>
    
    <?php xxx(102) ;
    // 0
    ?>

    Do you have any sugesstions?


    Robin W
    Moderator

    @robin-w

    try this

    function rew_count_threaded_replies ($reply_id = 0) {
    	$meta_key = '_bbp_reply_to' ;
    	global $wpdb;
    	$user_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->postmeta where meta_key='$meta_key' AND meta_value = '$reply_id'" );
    	echo $user_count ;
    }

    eigodeasobo
    Participant

    @eigodeasobo

    I really appreciate what you’ve done for me. Thank you!!!


    Robin W
    Moderator

    @robin-w

    great – glad you are fixed

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