How To: Nested Loopers w/ Parent/Child CPT relationships

This will be so much easier to show than to tell but, here’s the basic idea:

  1. I have A CPT called “Locations” which allow for parent/child relationships.
  2. I want to create all 50 States and nest certain Regions under them.
  3. I want to create a looper which will go and get the titles of each State and place them in columns (easy)
  4. Then in a list under each State name, another looper to go a get only those Regions which are a children of that State.

So, North Carolina has a column returned by the first looper which outputs “North Carolina”. South Carolina has a second column which out puts "“South Carolina”. AND under each one is listed the children of each.

North Carolina
-Charlotte
-Monroe
-Asheville

South Carolina
-Greenville
-Columbia

How can this be setup to work like I am describing?
Here’s a short video fro clarity:

Thank you!

Hi @simeoned,

Thanks for reaching out.
To check the setting you have in your Looper Provider, can you please share the following details in the secure note to examine it further, including:

– WordPress Site URL & Login URL
– WordPress Admin username/password

To create a secure note, click the key icon underneath any of your posts.

Thanks

@tristup
The Secure note has been created for you to look around. A few details I wanted to bring up.

  1. Please have a look here at the sandbox I setup for you: https://gestaltcreations.com/fia/sandbox/
    a. The first section has a manually build example of what I am trying to do exactly.
    b. The second section has what I am trying to do dynamically but don’t have working yet.

  2. In that second section, the “First Looper” is the one using a Custom Provider Type referencing the following hook in my functions.php file

     // For Themeco Sandbox
     add_filter('cs_looper_custom_locations', function($result, $args) {
     return get_posts( 
     array(
     	'post_type' => 'locations',
     	'numberposts' => -1,
     	'orderby' => 'title',
     	'order' => 'ASC',
     	'post_parent' => 0
     )
    );
    }, 10, 2);  
    

Note that I’ve limited the query to output just the parent posts.

  1. Finally the third section is where I echoed out the performed objects so we could see the data and how to potentially use it for the purposes I am describing. The custom shortcode I used for this is build in functions.php as well and looks like this:

    // For Themeco Sandbox
    function sandbox_output( $atts ){
    
    $posts = get_posts( 
     array(
     	'post_type' => 'locations',
     	'numberposts' => -1,
     	'orderby' => 'title',
     	'order' => 'ASC',
     	// 'post_parent' => 0
     )
    );
    
    echo '<pre>';
    print_r($posts);
    echo '</pre>';
    }
    add_shortcode( 'get_posts', 'sandbox_output' );
    

Not the query here is NOT limited to the parents of the post type only. This is so we can see everything in question and the relationship between them.

Hi @simeoned,

Unfortunately, the browser level restriction credentials are not provided and the current credentials do not work with it. I would suggest you check and provide the credentials for it.

Thanks

Secure note added… sorry about that.

Hello @simeoned,

It seems that the parent post id is not passed into the Nested Looper. This can be achieved by customization and that is beyond the scope of theme support. I would suggest you hire a developer who can assist you to do the customization or you can avail of our newly launched service called One, where the customization questions are answered.

Thanks for understanding

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.