• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

genesis_custom_loop and is_main_query?

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › genesis_custom_loop and is_main_query?

This topic is: not resolved

Tagged: custom loop, genesis_custom_loop

  • This topic has 1 reply, 2 voices, and was last updated 7 years, 2 months ago by Victor Font.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • March 14, 2016 at 1:53 am #181384
    trash
    Participant

    Hello,
    within my functions.php I created a different loop with genesis_custom_loop for a custom post type and its taxonomies, like this:

    function book_cat_archive_loop() {
    	$taxonomies = get_taxonomy_hierarchy('book-category');
    	foreach ($taxonomies as $tax_obj) {
    		//get all posts within taxonomy
    		$args = 	array('post_type' => 'book',
    		  				'tax_query' => array(
    			  				array(
    				                'taxonomy' => 'book-category',
    				                'field' => 'slug',
    				                'terms' => $tax_obj->slug,
    				            ),
    						),
    					);
    		genesis_custom_loop($args);
    	    wp_reset_query();
    	}//foreach
    }//function

    Within another function I have this code: (it returns $classes on the pages where I do not want to have the grid view)

    	if( ( ! $grid_args || ! $wp_query->is_main_query() )
    		return $classes;

    This will be true, because genesis_custom_loop seems to be not the main_query. I therefore have to change the request like this:
    if( ( ! $grid_args || ! $wp_query->is_main_query() ) && !$wp_query->is_post_type_archive() )

    How can I ensure that the loop within genesis_custom_loop is my main query? I do not fully understand why it is not my main query...

    Can somebody enlighten me please?

    Thanks!

    March 14, 2016 at 11:38 am #181423
    Victor Font
    Moderator

    When WordPress sets up the main query it stores it in two variables: $wp_the_query and $wp_query. The Genesis Custom loop alters the $wp_query variable. is_main_query() compares the value of the current query against $wp_the_query. In your case, since $wp_query <> $wp_the_query, is_main_query() properly returns false.


    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

  • Author
    Posts
Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble