bp_core_filter_wp_query( null $retval, WP_Query $query )
Stop WordPress performing a DB query for its main loop.
Description
As of WordPress 4.6, it is possible to bypass the main WP_Query entirely. This saves us one unnecessary database query! 🙂
Parameters
- $retval
-
(null) (Required) Current return value for filter.
- $query
-
(WP_Query) (Required) Current WordPress query object.
Return
(null|array)
Source
File: bp-core/bp-core-catchuri.php
function bp_core_filter_wp_query( $retval, $query ) { if ( ! $query->is_main_query() ) { return $retval; } /* * If not on a BP single page, bail. * Too early to use bp_is_single_item(), so use BP conditionals. */ if ( false === ( bp_is_group() || bp_is_user() || bp_is_single_activity() ) ) { return $retval; } // Set default properties as recommended in the 'posts_pre_query' DocBlock. $query->found_posts = 0; $query->max_num_pages = 0; // Return something other than a null value to bypass WP_Query. return array(); }
Changelog
Version | Description |
---|---|
BuddyPress 2.7.0 | Introduced. |
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.