bp_core_filter_wp_query

Stop WordPress performing a DB query for its main loop.

Description

(null|array) bp_core_filter_wp_query( (null) $retval, (WP_Query) $query ); 

As of WordPress 4.6, it is possible to bypass the main WP_Query entirely. This saves us one unnecessary database query! :)

Returns (null|array)

Parameters (2)

0. $retval (null)
Current return value for filter.
1. $query (WP_Query)
Current WordPress query object.

Usage

  1. if ( !function_exists( 'bp_core_filter_wp_query' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-catchuri.php'; 
  3.  
  4. // Current return value for filter. 
  5. $retval = null; 
  6.  
  7. // Current WordPress query object. 
  8. $query = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bp_core_filter_wp_query($retval, $query); 
  12.  

Defined (1)

The function is defined in the following location(s).

/bp-core/bp-core-catchuri.php  
  1. function bp_core_filter_wp_query( $retval, $query ) { 
  2. if ( ! $query->is_main_query() ) { 
  3. return $retval; 
  4.  
  5. /** 
  6. * If not on a BP single page, bail. 
  7. * Too early to use bp_is_single_item(), so use BP conditionals. 
  8. */ 
  9. if ( false === ( bp_is_group() || bp_is_user() || bp_is_single_activity() ) ) { 
  10. return $retval; 
  11.  
  12. // Set default properties as recommended in the 'posts_pre_query' DocBlock. 
  13. $query->found_posts = 0; 
  14. $query->max_num_pages = 0; 
  15.  
  16. // Return something other than a null value to bypass WP_Query. 
  17. return array();