bbp_get_public_child_ids( int $parent_id, string $post_type = 'post' )
Query the DB and get a the child id’s of public children
Description
Parameters
- $parent_id
-
(Required) Parent id
- $post_type
-
(Optional) Post type. Defaults to 'post'
Default value: 'post'
Return
(array) The array of children
Source
File: bp-forums/common/functions.php
1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 | function bbp_get_public_child_ids( $parent_id = 0, $post_type = 'post' ) { global $wpdb ; // Bail if nothing passed if ( empty ( $parent_id ) ) return false; // The ID of the cached query $cache_id = 'bbp_parent_public_' . $parent_id . '_type_' . $post_type . '_child_ids' ; // Check for cache and set if needed $child_ids = wp_cache_get( $cache_id , 'bbpress_posts' ); if ( false === $child_ids ) { $post_status = array ( bbp_get_public_status_id() ); // Add closed status if topic post type if ( $post_type === bbp_get_topic_post_type() ) { $post_status [] = bbp_get_closed_status_id(); } // Join post statuses together $post_status = "'" . implode( "', '" , $post_status ) . "'" ; $child_ids = $wpdb ->get_col( $wpdb ->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status 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_public_child_ids' , $child_ids , $parent_id , $post_type ); } |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.