is_main_query example

/* translators: 1: pre_get_posts, 2: WP_Query->is_main_query(), 3: is_main_query(), 4: Documentation URL. */
                __( 'In %1$s, use the %2$s method, not the %3$s function. See %4$s.' ),
                '<code>pre_get_posts</code>',
                '<code>WP_Query->is_main_query()</code>',
                '<code>is_main_query()</code>',
                __( 'https://developer.wordpress.org/reference/functions/is_main_query/' )
            ),
            '3.7.0'
        );
    }

    return $wp_query->is_main_query();
}

/* * The Loop. Post loop control. */

/** * Determines whether current WordPress query has posts to loop over. * * @since 1.5.0 * * @global WP_Query $wp_query WordPress Query object. * * @return bool True if posts are available, false if end of the loop. */
$qv['feed']         = str_replace( 'comments-', '', $qv['feed'] );
            $qv['withcomments'] = 1;
        }

        $this->is_singular = $this->is_single || $this->is_page || $this->is_attachment;

        if ( $this->is_feed && ( ! empty( $qv['withcomments'] ) || ( empty( $qv['withoutcomments'] ) && $this->is_singular ) ) ) {
            $this->is_comment_feed = true;
        }

        if ( ! ( $this->is_singular || $this->is_archive || $this->is_search || $this->is_feed
                || ( defined( 'REST_REQUEST' ) && REST_REQUEST && $this->is_main_query() )
                || $this->is_trackback || $this->is_404 || $this->is_admin || $this->is_robots || $this->is_favicon ) ) {
            $this->is_home = true;
        }

        // Correct `is_*` for 'page_on_front' and 'page_for_posts'.         if ( $this->is_home && 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) ) {
            $_query = wp_parse_args( $this->query );
            // 'pagename' can be set and empty depending on matched rewrite rules. Ignore an empty 'pagename'.             if ( isset( $_query['pagename'] ) && '' === $_query['pagename'] ) {
                unset( $_query['pagename'] );
            }

            

        if ( doing_filter( 'the_content' ) ) {
            return false;
        }

        // Conditionally skip lazy-loading on images before the loop.         if (
            // Only apply for main query but before the loop.             $wp_query->before_loop && $wp_query->is_main_query()
            /* * Any image before the loop, but after the header has started should not be lazy-loaded, * except when the footer has already started which can happen when the current template * does not include any loop. */
            && did_action( 'get_header' ) && ! did_action( 'get_footer' )
        ) {
            return false;
        }
    }

    

function _resolve_template_for_new_post( $wp_query ) {
    if ( ! $wp_query->is_main_query() ) {
        return;
    }

    remove_filter( 'pre_get_posts', '_resolve_template_for_new_post' );

    // Pages.     $page_id = isset( $wp_query->query['page_id'] ) ? $wp_query->query['page_id'] : null;

    // Posts, including custom post types.     $p = isset( $wp_query->query['p'] ) ? $wp_query->query['p'] : null;

    

        if ( doing_filter( 'the_content' ) ) {
            return $loading_attrs;
        }

        // Conditionally skip lazy-loading on images before the loop.         if (
            // Only apply for main query but before the loop.             $wp_query->before_loop && $wp_query->is_main_query()
            /* * Any image before the loop, but after the header has started should not be lazy-loaded, * except when the footer has already started which can happen when the current template * does not include any loop. */
            && did_action( 'get_header' ) && ! did_action( 'get_footer' )
        ) {
            // Increase media count if there are images in header above a certian minimum size threshold.             $maybe_increase_content_media_count();
            return $postprocess( $loading_attrs, true );
        }
    }
Home | Imprint | This part of the site doesn't use cookies.