bbp_get_all_child_ids (intparent_id美元,字符串post_type美元=“职位”)
查询DB并获得所有子节点的子节点id
描述
参数
- parent_id美元
-
(int)(必需)父id
- post_type美元
-
(字符串)(可选)文章类型。默认为“发布”
默认值:“文章”
返回
(数组)一群孩子
源
函数bbp_get_all_child_ids($parent_id = 0, $post_type = 'post') {global $wpdb;if (empty($parent_id))返回false;//缓存查询的ID $cache_id = 'bbp_parent_all_'。parent_id美元。“_type_”。post_type美元。“_child_ids”;$cache_id = wp_cache_get($cache_id, 'bbpress_posts');$not_in = array('draft', 'future');$post_status = "'"。 implode( "', '", $not_in ) . "'"; $child_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status NOT IN ( {$post_status} ) AND post_type = '%s' ORDER BY ID DESC;", $parent_id, $post_type ) ); wp_cache_set( $cache_id, $child_ids, 'bbpress_posts' ); } // Filter and return return apply_filters( 'bbp_get_all_child_ids', $child_ids, (int) $parent_id, $post_type ); }