bbp_get_public_child_last_id( int $parent_id, string $post_type = 'post' )
Query the DB and get the last public post_id that has parent_id as post_parent
Description Description
Parameters Parameters
- $parent_id
-
(Required) Parent id.
- $post_type
-
(Optional) Post type. Defaults to 'post'.
Default value: 'post'
Return Return
(int) The last active post_id
Source Source
File: includes/common/functions.php
function bbp_get_public_child_last_id( $parent_id = 0, $post_type = 'post' ) { // Bail if nothing passed if ( empty( $parent_id ) ) { return false; } // 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 'suppress_filters' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'ignore_sticky_posts' => true, 'no_found_rows' => true ) ); $child_id = array_shift( $query->posts ); unset( $query ); // Filter & return return (int) apply_filters( 'bbp_get_public_child_last_id', $child_id, $parent_id, $post_type ); }
Changelog Changelog
Version | Description |
---|---|
2.6.0 | bbPress (r5954) Replace direct queries with WP_Query() objects |
2.0.0 | Introduced. |