Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to set limits on the number of replies to topics


  • eigodeasobo
    Participant

    @eigodeasobo

    Hi,

    I’d like to restrict the reply to 100 cases, but is there a way?

    For example, I want to make it .bbp-reply-to-link{display:none;} when comment becomes 100 or more.

    However, since only 15 replies are displayed on one page, JS can not count comments on loading.

    So, It’s best if you can do that with PHP settings…

    What should I do?

    Thanks.

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

  • Robin W
    Moderator

    @robin-w

    add this to your functions file, it closes the topic when the 100th reply is posted

    add_action( 'bbp_new_reply_post_extras', 'rew_close_topic' );
    
    function rew_close_topic ($reply_id) {
    //  find out the topic_id
    $topic_id = bbp_get_reply_topic_id ($reply_id) ;
    $count = bbp_get_topic_reply_count ($topic_id) ;
    if ($count == 100) bbp_close_topic( $topic_id );
    }

    eigodeasobo
    Participant

    @eigodeasobo

    Hi, Thanks for the reply.

    But that code did not close.

    So, I wrote the following code for now.

    <p id="replies_count"><?php bbp_topic_reply_count(); ?></p>
    <script>
    (function($){
      var replies_count = $('#replies_count').text();
      if( replies_count >= 100 ){
        $('.bbp-reply-to-link').css('display','none');
      }
    })(jQuery);
    </script>

    However, It’s incomplete just because it is hidden, so I would like to close it as well.

    Please let me know again if there is another code.

    Thanks.


    Robin W
    Moderator

    @robin-w

    that code will close the topic on 100 replies, so unless you tested with creating the 100th reply, then it would not work. Did you do this ?


    eigodeasobo
    Participant

    @eigodeasobo

    I changed that number from 100 to 10 and posted over 11 replies.

    if ($count == 100) bbp_close_topic( $topic_id );

    if ($count == 10) bbp_close_topic( $topic_id );

    However, it was not closed.

    Thanks.


    Robin W
    Moderator

    @robin-w

    ok, I cannot say why it is not working, it works in my test site

    I presume this code is going into you child theme’s function’s file – sorry but I do not know how technical you are, so I ask the obvious questions !

    you could try >9 and see if that works !


    eigodeasobo
    Participant

    @eigodeasobo

    Hi,
    Unfortunately, it didn’t work out.

    add_action( 'bbp_new_reply_post_extras', 'rew_close_topic' );
    
    function rew_close_topic ($reply_id) {
    //  find out the topic_id
    $topic_id = bbp_get_reply_topic_id ($reply_id) ;
    $count = bbp_get_topic_reply_count ($topic_id) ;
    if ($count >9) bbp_close_topic( $topic_id );
    }

    If you have further information, please let me know.
    Thanks.


    Robin W
    Moderator

    @robin-w

    ok, sorry I can’t say why it is not working on your site


    eigodeasobo
    Participant

    @eigodeasobo

    Thank you for helping me:)

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