Skip to:

Forum reply permalink issue

  • giannis4


    Hello all,

    I am using BuddyPress (v5.0.0.) with bbPress (v.2.5.14) and I am noticing an issue when I have a forum topic with multiple pages. When I add a new reply it creates a BuddyPress activity that stores in the DB a primary_link of the type /forums/topic/topic-name/page/XX/#post-YYYY. For example /forums/topic/test-notification-for-reply/page/2/#post-3063

    The problem is that if I delete some previous replies from page 1 and this reply moves to the first page from the second page it was previously, its activity permalink (primary_link) remains the same and the activity still points to page 2 of the topic (not page 1 that is its new page).

    Is there any fix for this?

Viewing 1 replies (of 1 total)

  • giannis4


    I found the problem and fix. First, the problem happened because when a reply was deleted it did not refresh the ‘menu_order’ value of the other replies that is used to calculate the reply’s page in its permalink.

    To fix this I have added a hook to bbp_delete_reply action that resets the menu order of all replies that belong to the same topic as the deleted reply. This refreshes there menu order and the permalinks show the correct URL.

    The code:

    function gkco_reset_all_topic_replies_link_on_reply_delete( $reply_id ) {
        global $wpdb;
        // Reset all topic's replies menu_order
        $sql = sprintf( 'UPDATE ' . $wpdb->posts . ' SET menu_order = 0 WHERE post_parent = %d AND post_type = "reply"', bbp_get_topic_id() );
        $result = $wpdb->query( $sql );
    add_action( 'bbp_delete_reply', 'gkco_reset_all_topic_replies_link_on_reply_delete' );
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.
Skip to toolbar