Changeset 2891 for branches/plugin/bbp-includes/bbp-general-functions.php
- Timestamp:
- 02/13/2011 11:09:50 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/plugin/bbp-includes/bbp-general-functions.php
r2877 r2891 1058 1058 $cache_id = 'bbp_parent_' . $parent_id . '_type_' . $post_type . '_child_last_id'; 1059 1059 1060 if ( !$child_id = wp_cache_get( $cache_id ) ) {1060 if ( !$child_id = wp_cache_get( $cache_id, 'bbpress' ) ) { 1061 1061 $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 ) ); 1062 1062 wp_cache_set( $cache_id, $child_id, 'bbpress' ); … … 1067 1067 1068 1068 /** 1069 * Query the DB and get a count of activepublic children1069 * Query the DB and get a count of public children 1070 1070 * 1071 1071 * @global db $wpdb … … 1075 1075 */ 1076 1076 function bbp_get_public_child_count( $parent_id = 0, $post_type = 'post' ) { 1077 global $wpdb ;1077 global $wpdb, $bbp; 1078 1078 1079 1079 if ( empty( $parent_id ) ) … … 1083 1083 $cache_id = 'bbp_parent_' . $parent_id . '_type_' . $post_type . '_child_count'; 1084 1084 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 ) ); 1087 1087 wp_cache_set( $cache_id, $child_count, 'bbpress' ); 1088 1088 } … … 1091 1091 } 1092 1092 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 */ 1101 function 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 1093 1118 ?>
Note: See TracChangeset
for help on using the changeset viewer.