bbp_get_public_child_ids( int $parent_id, string $post_type = 'post' )
Query the DB and get the child id’s of public children
Description Description
Parameters Parameters
- $parent_id
-
(Required) Parent id.
- $post_type
-
(Optional) Post type. Defaults to 'post'.
Default value: 'post'
Return Return
(array) The array of children
Source Source
File: includes/common/functions.php
function bbp_get_public_child_ids( $parent_id = 0, $post_type = 'post' ) { // Bail if nothing passed if ( empty( $parent_id ) || empty( $post_type ) ) { return array(); } // Which statuses switch ( $post_type ) { // Forum case bbp_get_forum_post_type() : $post_status = bbp_get_public_forum_statuses(); break; // Topic case bbp_get_topic_post_type() : $post_status = bbp_get_public_topic_statuses(); break; // Reply case bbp_get_reply_post_type() : default : $post_status = bbp_get_public_reply_statuses(); break; } $query = new WP_Query( array( 'fields' => 'ids', 'post_parent' => $parent_id, 'post_status' => $post_status, 'post_type' => $post_type, 'posts_per_page' => -1, 'orderby' => array( 'post_date' => 'DESC', 'ID' => 'DESC' ), // Performance 'nopaging' => true, 'suppress_filters' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'ignore_sticky_posts' => true, 'no_found_rows' => true ) ); $child_ids = ! empty( $query->posts ) ? $query->posts : array(); unset( $query ); // Filter & return return (array) apply_filters( 'bbp_get_public_child_ids', $child_ids, $parent_id, $post_type ); }
Changelog Changelog
Version | Description |
---|---|
2.6.0 | bbPress (r5954) Replace direct queries with WP_Query() objects |
2.0.0 | Introduced. |