is_main_query

Is the query the main query?.

Description

is_main_query(); 

Usage

  1. if ( !function_exists( 'is_main_query' ) ) { 
  2. require_once ABSPATH . WPINC . '/query.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = is_main_query(); 
  7.  

Defined (1)

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

/wp-includes/query.php  
  1. function is_main_query() { 
  2. if ( 'pre_get_posts' === current_filter() ) { 
  3. $message = sprintf( 
  4. /** translators: 1: pre_get_posts 2: WP_Query->is_main_query() 3: is_main_query() 4: link to codex is_main_query() page. */ 
  5. __( 'In %1$s, use the %2$s method, not the %3$s function. See %4$s.' ),  
  6. '<code>pre_get_posts</code>',  
  7. '<code>WP_Query->is_main_query()</code>',  
  8. '<code>is_main_query()</code>',  
  9. __( 'https://codex.wordpress.org/Function_Reference/is_main_query' ) 
  10. ); 
  11. _doing_it_wrong( __FUNCTION__, $message, '3.7.0' ); 
  12.  
  13. global $wp_query; 
  14. return $wp_query->is_main_query();