Reply To: Forum reply permalink issue
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' );