Skip to:
Content
Pages
Categories
Search
Top
Bottom

Reverse order replies and pagination

  • @webmasterfreya

    Participant

    Hi,

    I have the following code in my themes functions.php
    function bbp_reverse_reply_order( $query = array() ) { // bbp_has_replies_query is depricated ?
    $query['order']='DESC';
    return $query;
    }
    add_filter('bbp_has_replies_query','bbp_reverse_reply_order');

    This works fine except when a new reply is added, you get redirected to the page with the oldest replies instead of the page that contains the just added reply. This seems to be an old problem, have tried various plugins, but they all lead to the same outcome.

    So the question is how to force, after adding a new reply, to be directed to the right page.

    site freya.nl, latest versions WordPress and bbPress.

Viewing 16 replies - 1 through 16 (of 16 total)
  • @webmasterfreya

    Participant

    No replies for 17 months 🙁

    Some thoughts:

    Also the notification emails contain a wrong link (highest page number instead of first)

    Sends notification emails for new replies to subscribed topics
    \wp-content\plugins\bbpress\includes\common\functions.php

    1061 function bbp_notify_topic_subscribers

    1101 $reply_url = bbp_get_reply_url( $reply_id );

    if the order =’DESC’ for replies maybe then use bbp_get_topic_permalink as $reply_url ?

    As mentioned above after adding a new reply to a topic one should also be redirected to the first page (bbp_get_topic_permalink ?)

    Probably there are some more places where the same should apply.

    @traverser11

    Participant

    Checking in because I want this too… there was a plugin called ‘bbpress sort topic replies’, that no longer works, but I’m going to try to grab the code from that

    @traverser11

    Participant

    I gave it a go, and it kinda worked, lol…
    But this reverses all the replies INCLUDING the original topic.
    So the original topic goes to the bottom…
    What I would ideally want is the Topic, THEN the replies in reverse order…

    // Reverse reply order on News topic
    
    add_filter('bbp_has_replies_query','bbp_reverse_reply_order');
    function bbp_reverse_reply_order( $query = array() ) {
    	// Identify post type
    	$bbPress_post_id = get_the_ID();
    	$bbPress_post_type = get_post_type($bbPress_post_id);
    
    	if( $bbPress_post_type =='topic' ){
    
    		/** TOPIC **/
    			$query['order']='DESC';
    			return $query;
    
      }
    };

    @robin-w

    Moderator

    @webmasterfreya

    Participant

    Thanks for your work ‘Back to Front’.

    Did you also test for the right links to the right page (so when having multiple pages of replies, after adding a new reply one should end up at the first page not the last?

    @traverser11

    Participant

    Thanks again @robin-w and @webmasterfreya

    I ended up deleting the part causing errors from ‘bbpress sort topic replies’ plugin, and that works – (for topics not for forums though)… Its nice because it gives the ‘show lead topic’ and reply sort order in the admin meta box. Can share somewhere if its useful.

    But yes now I see what you mean! that upon posting the newest reply, it redirects to the last page of the pagination, which in the case of replies descending by date, makes no sense. Sorry for hijacking your topic!

    Hmmm any ideas where to start on this?

    @traverser11

    Participant

    Oh here is an answer!

    Wrong bbp_get_reply_url() when paging with reverse order

    This snippet works – i’m just a bit confused how to turn it on when replies are descending and off when they are ascending…

    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
    }

    @robin-w

    Moderator

    @traverser11 – great that you are posting the answers here – so many don’t 🙂 🙂 🙂

    can you summarise where you are at, so eg

    use this plugin (are you still using the sort topic replies plugin?)
    delete this code from it
    add this code to this place

    etc.

    so it is all in one thread, I’ll then try to give to some switch on and off code

    @webmasterfreya

    Participant

    Works! It seems to me that this works for both ASC and DESC sort.

    @webmasterfreya

    Participant

    Hi,

    Your piece of code has an unwanted side effect. When looking at a subscriber as admin the created replies of this subscriber do not show anymore.
    I reverted back to the original code (on top of this topic) and presto the replies of the subscriber show up again.

    @traverser11

    Participant

    I’m confused about which archive you are looking at that causes this problem?
    Sorry I got busy with my other jobs but I’ll come back to this, lets get it sorted!

    @webmasterfreya

    Participant

    Hi Back to Front,

    I also have buddypress installed. As admin you have for each member a page wich among other things shows topics started and replies made by the member. The replies did not show up (and there were definitly replies).

    As buddypress makes use of bbpress for fora i expected your code to work but it did not (is the culprit then buddypress or bbpress or your code? I haven’t the faintest idea).

    Maybe : if( $bbPress_post_type ==’topic’ ){

    /** TOPIC **/
    $query[‘order’]=’DESC’;
    return $query;

    should have an } else {return $query}

    @traverser11

    Participant

    Hi sorry its been a while! Been busy with other projects.


    @robin-w
    @webmasterfreya this is what I’ve done to reverse the reply order on certain topics. And now I’ve come back to it after a month, I can’t reproduce the issue of it breaking the pagination. It seems to work as expected, without adding another function to mess with the pagination.

    Install

    bbPress – Sort topic replies

    Remove the parts that sort the forum’s topic order, as they are causing errors, and they aren’t desired for this purpose (sorting the reply order)

    // Adds meta box to the side bar of the Forums edit pages
    add_action( 'add_meta_boxes', 'bbPress_meta_box_add' );
    function bbPress_meta_box_add(){
    	add_meta_box( 'bbPress_meta_box_sort_desc', 'Sort Replies', 'bbPress_forum_meta_box', 'forum', 'side', 'high' );
    }
    

    and

    	// Save sort settings for forum
    		if( $_POST['str-bbpress-sort-replies'] == "desc" ){
    			update_post_meta($post_id, '_bbp_sort_desc', 'desc');
    		}elseif( $_POST['str-bbpress-sort-replies'] == "asc" ){
    			update_post_meta($post_id, '_bbp_sort_desc', 'asc');
    		}else{
    			update_post_meta($post_id, '_bbp_sort_desc', 'dft');
    		}
    

    and

    	// Save show lead settings for the forum
    		if( $_POST['str-bbpress-sort-replies-show-lead-topic-forum'] == "yes" ){
    			update_post_meta($post_id, '_bbp_topic_sort_show_lead_topic_forum', 'yes');
    		}elseif( $_POST['str-bbpress-sort-replies-show-lead-topic-forum'] == "no" ){
    			update_post_meta($post_id, '_bbp_topic_sort_show_lead_topic_forum', 'no');
    		}else{
    			update_post_meta($post_id, '_bbp_topic_sort_show_lead_topic_forum', 'dft');
    		}
    

    I can send the whole file if thats more useful.

    Sorry I hope i’m not missing something that we noticed before? Actually my site is using threaded replies. So unfortunately it’s not using pagination, its unfortunate it can’t have both. But I turned it off to test this and it it worked.

    Regarding the buddypress activity stream…
    Here is an example of a member page with buddypress activity stream.
    https://houseonfire.backtofrontdesign.co/members/forum_2tbmmm/
    I think it also works as expected showing forum replies in the reverse chronological order.

    @traverser11

    Participant

    Oh sorry I’m wrong. Quite confused!

    The pagination issue is not resolved, i just didn’t remember the issue, duh.

    So reminding myself, the issue is, with the reply order set to descending, upon posting a new reply, it tries to redirect to the anchor of the that reply, but it goes to first reply on the last page of the pagination. Has me stumped!

    @scratchy101

    Participant

    I’m having the same issue.
    I have the post sort order set to descending and posts per page set to 25.
    On multi-page threads (more than 25 posts) the pagination works correctly for most links except the “Last Post” link. When users click on the link under last post column, they are taken to the last page instead of the first page with the newest reply.
    Would this plugin resolve this issue?
    Or can I edit a PHP file to fix this?

    @scratchy101

    Participant

    BTW, I’m using this plugin to sort by descending order.

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