Skip to:
Content

bbPress.org

Changeset 7292


Ignore:
Timestamp:
04/16/2025 06:00:44 PM (2 months ago)
Author:
johnjamesjacoby
Message:

Replies: Fix a bug that causes replies to not appear in some topics.

In WordPress 6.8, WP_Query now enforces a consistent alphabetical order for array values. This change breaks the _bbp_has_replies_where() function, which previously relied on a strict comparison against post_type.

See: https://core.trac.wordpress.org/ticket/59516

This commit replaces the strict comparison with an array_diff() check to account for the new behavior. It also optimizes the surrounding logic to minimize repeated calls to $query->get().

Props @vortfu.

Committed to the 2.6 branch for 2.6.13.

See #3631.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.6/src/includes/replies/functions.php

    r7255 r7292  
    20842084    }
    20852085
    2086     // Bail if no post_parent to replace
    2087     if ( ! is_numeric( $query->get( 'post_parent' ) ) ) {
    2088         return $where;
    2089     }
    2090 
    2091     // Bail if not a topic and reply query
    2092     if ( array( bbp_get_topic_post_type(), bbp_get_reply_post_type() ) !== $query->get( 'post_type' ) ) {
    2093         return $where;
    2094     }
    2095 
    20962086    // Bail if including specific post ID's
    20972087    if ( $query->get( 'post__in' ) ) {
     
    20992089    }
    21002090
     2091    // Get post_parent from query (used to get the topic ID below)
     2092    $post_parent = $query->get( 'post_parent' );
     2093
     2094    // Bail if post_parent is default '' (uses is_numeric() because WordPress does internally)
     2095    if ( ! is_numeric( $post_parent ) ) {
     2096        return $where;
     2097    }
     2098
     2099    // Get post_type from query, define array to diff against
     2100    $queried_types = (array) $query->get( 'post_type' );
     2101    $post_types    = array( bbp_get_topic_post_type(), bbp_get_reply_post_type() );
     2102
     2103    // Bail if query is not already for both topic and reply post types
     2104    if ( array_diff( $post_types, $queried_types ) ) {
     2105        return $where;
     2106    }
     2107
    21012108    /** Proceed ***************************************************************/
    21022109
     
    21052112
    21062113    // Get the topic ID from the post_parent, set in bbp_has_replies()
    2107     $topic_id   = bbp_get_topic_id( $query->get( 'post_parent' ) );
     2114    $topic_id   = bbp_get_topic_id( $post_parent );
    21082115
    21092116    // The texts to search for
Note: See TracChangeset for help on using the changeset viewer.