Skip to:
Content
Pages
Categories
Search
Top
Bottom

Wrong bbp_get_reply_url() when paging with reverse order


  • gperez-tl
    Participant

    @gperez-tl

    Hi.
    I’m showing my replies as a timestream, meaning I display the newest replies above the oldest one. Like this:

    function custom_bbp_reorder_replies($args) { 
        
      $args['order'] = 'DESC'; // 'ASC' (Ascending, Default), 'DESC' (Descending) 
      return $args;
    }
    add_filter('bbp_before_has_replies_parse_args', 'custom_bbp_reorder_replies' );

    Well, in My Replies Created I’m showing a list of replies with a link to corresponding thread like this:

    <a href=" <?php echo bbp_get_reply_url() ?>" class="bbp-topic-edit-link">...</a>

    But that is not working because bbp_get_reply_url() is considering default order instead of reverse. So, when doing this it returns the wrong page:

    $reply_page = ceil( (int) bbp_get_reply_position( $reply_id, $topic_id ) / (int) bbp_get_replies_per_page() );

    (that code is in includes/replies/template.php, line 487)

    Maybe a hook around there would help.

    By now I’m not sure how to solve it for myself.

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

  • gperez-tl
    Participant

    @gperez-tl

    I think this works:

    add_filter('bbp_get_reply_position', 'lugpa_get_reply_position', 10, 3);
    function lugpa_get_reply_position($reply_position, $reply_id, $topic_id){
        
        if(empty($topic_id))
            $topic_id = bbp_get_reply_topic_id ($reply_id);
        
        $numReplies = bbp_get_topic_reply_count($topic_id);
        return ($numReplies+1) - $reply_position; // plus one because of thread description
    }

    I’m not sure about the +1 but it works. I tested this with first and last comment of a given page.

    Hi,
    with just this small portion of the code, it’s difficult to see the whole loop/picture of course. I’m not sure of what you try to obtain, but just one thing to start from your first one (custom_bbp_reorder_replies), to inverse the order I used:

    if ( bbp_is_single_topic() && !bbp_is_single_user() ) { 
       $args['orderby'] .= 'post_modified';
       $args['order'] .= 'DESC';
    }

    Pascal.


    Robkk
    Moderator

    @robkk

    @gperez-tl

    Good find on this bug, and thanks for posting your temporary solution. I tried the solution and it works for most of the replies, while I was testing I got some that seemed to not work and it went to the wrong post still.

    The error is not only present in the replies created section in your forum profile but also if you click the post id next to a reply (#1234), you might be directed to the wrong reply.

    I tried this on the latest dev version of 2.6 and this issue is not present.


    kypo
    Participant

    @kypo

    Hi All.

    I think that I have a similar problem, maybe the same problem.
    If anyone advise me I will be very grateful.
    Unfortunately I am not a programmer and I can not help myself.

    I tried to insert this code from @gperez-tl

    add_filter('bbp_get_reply_position', 'lugpa_get_reply_position', 10, 3);
    function lugpa_get_reply_position($reply_position, $reply_id, $topic_id){
        
        if(empty($topic_id))
            $topic_id = bbp_get_reply_topic_id ($reply_id);
        
        $numReplies = bbp_get_topic_reply_count($topic_id);
        return ($numReplies+1) - $reply_position; // plus one because of thread description
    }

    into my theme functions.php but it does not work for me.

    For example, in this topic:

    3.1.2016 Supercars @ Brands Hatch

    Links to first posts (#9129) refers to the wrong url to page2, but this post is still on page1…
    Other post urls on this page1 is OK. When i go to page2 every post has bad URL refers to page1.

    Please help if you can… Thanks

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