Skip to:
Content

bbPress.org


Ignore:
Timestamp:
08/07/2017 08:23:18 PM (9 years ago)
Author:
johnjamesjacoby
Message:

Query: use NOT IN strategy in bbp_get_all_child_ids()

This ensures that only specific post-statuses are explicitly excluded from "all child IDs" type queries, where previously post-statuses needed to be specifically defined.

See #3128.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/common/functions.php

    r6616 r6643  
    16081608
    16091609/**
    1610  * Query the DB and get a the child id's of all children
     1610 * Query the DB and get the child id's of all children
    16111611 *
    16121612 * @since 2.0.0 bbPress (r3325)
     
    16321632    $child_ids = wp_cache_get( $cache_key, 'bbpress_posts' );
    16331633    if ( false === $child_ids ) {
    1634         $post_status = array( bbp_get_public_status_id() );
    1635 
    1636         // Extra post statuses based on post type
    1637         switch ( $post_type ) {
    1638 
    1639             // Forum
    1640             case bbp_get_forum_post_type() :
    1641                 $post_status[] = bbp_get_private_status_id();
    1642                 $post_status[] = bbp_get_hidden_status_id();
    1643                 break;
    1644 
    1645             // Topic
    1646             case bbp_get_topic_post_type() :
    1647                 $post_status[] = bbp_get_pending_status_id();
    1648                 $post_status[] = bbp_get_closed_status_id();
    1649                 $post_status[] = bbp_get_trash_status_id();
    1650                 $post_status[] = bbp_get_spam_status_id();
    1651                 break;
    1652 
    1653             // Reply
    1654             case bbp_get_reply_post_type() :
    1655                 $post_status[] = bbp_get_pending_status_id();
    1656                 $post_status[] = bbp_get_trash_status_id();
    1657                 $post_status[] = bbp_get_spam_status_id();
    1658                 break;
    1659         }
    1660 
    1661         // Join post statuses together
    1662         $post_status = "'" . implode( "', '", $post_status ) . "'";
     1634
     1635        // Join post statuses to specifically exclude together
     1636        $not_in      = array( 'draft', 'future' );
     1637        $post_status = "'" . implode( "', '", $not_in ) . "'";
    16631638        $bbp_db      = bbp_db();
    16641639
    16651640        // Note that we can't use WP_Query here thanks to post_status assumptions
    1666         $query       = $bbp_db->prepare( "SELECT ID FROM {$bbp_db->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = %s ORDER BY ID DESC", $parent_id, $post_type );
     1641        $query       = $bbp_db->prepare( "SELECT ID FROM {$bbp_db->posts} WHERE post_parent = %d AND post_status NOT IN ( {$post_status} ) AND post_type = %s ORDER BY ID DESC", $parent_id, $post_type );
    16671642        $child_ids   = (array) $bbp_db->get_col( $query );
    16681643
Note: See TracChangeset for help on using the changeset viewer.