Skip to:
Content

bbPress.org


Ignore:
Timestamp:
02/13/2011 11:09:50 AM (15 years ago)
Author:
johnjamesjacoby
Message:

Add bbp_get_public_child_ids function to retrieve an array of post_id's from any other post_id. Add 'bbpress' cache group to wp_cache_get calls so that cached values are actually returned.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-includes/bbp-general-functions.php

    r2877 r2891  
    10581058    $cache_id = 'bbp_parent_' . $parent_id . '_type_' . $post_type . '_child_last_id';
    10591059
    1060     if ( !$child_id = wp_cache_get( $cache_id ) ) {
     1060    if ( !$child_id = wp_cache_get( $cache_id, 'bbpress' ) ) {
    10611061        $child_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status = 'publish' AND post_type = '%s' ORDER BY ID DESC LIMIT 1;", $parent_id, $post_type ) );
    10621062        wp_cache_set( $cache_id, $child_id, 'bbpress' );
     
    10671067
    10681068/**
    1069  * Query the DB and get a count of active public children
     1069 * Query the DB and get a count of public children
    10701070 *
    10711071 * @global db $wpdb
     
    10751075 */
    10761076function bbp_get_public_child_count( $parent_id = 0, $post_type = 'post' ) {
    1077     global $wpdb;
     1077    global $wpdb, $bbp;
    10781078
    10791079    if ( empty( $parent_id ) )
     
    10831083    $cache_id = 'bbp_parent_' . $parent_id . '_type_' . $post_type . '_child_count';
    10841084
    1085     if ( !$child_count = wp_cache_get( $cache_id ) ) {
    1086         $child_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_parent = %d AND post_status = 'publish' AND post_type = '%s';", $parent_id, $post_type ) );
     1085    if ( !$child_count = wp_cache_get( $cache_id, 'bbpress' ) ) {
     1086        $child_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( '" . join( "', '", array( 'publish', $bbp->closed_status_id ) ) . "' ) AND post_type = '%s';", $parent_id, $post_type ) );
    10871087        wp_cache_set( $cache_id, $child_count, 'bbpress' );
    10881088    }
     
    10911091}
    10921092
     1093/**
     1094 * Query the DB and get a the child ID's of public children
     1095 *
     1096 * @global db $wpdb
     1097 * @param int $parent_id
     1098 * @param string $post_type
     1099 * @return int The number of children
     1100 */
     1101function bbp_get_public_child_ids( $parent_id = 0, $post_type = 'post' ) {
     1102    global $wpdb, $bbp;
     1103
     1104    if ( empty( $parent_id ) )
     1105        return false;
     1106
     1107    // The ID of the cached query
     1108    $cache_id = 'bbp_parent_' . $parent_id . '_type_' . $post_type . '_child_ids';
     1109
     1110    if ( !$child_ids = wp_cache_get( $cache_id, 'bbpress' ) ) {
     1111        $child_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( '" . join( "', '", array( 'publish', $bbp->closed_status_id ) ) . "' ) AND post_type = '%s' ORDER BY ID DESC;", $parent_id, $post_type ) );
     1112        wp_cache_set( $cache_id, $child_ids, 'bbpress' );
     1113    }
     1114
     1115    return apply_filters( 'bbp_get_public_child_ids', $child_ids, (int) $parent_id, $post_type );
     1116}
     1117
    10931118?>
Note: See TracChangeset for help on using the changeset viewer.