Support

Account

Home Forums General Issues Deeply nested post types Reply To: Deeply nested post types

  • Well, actually, getting information from a great-grandparent wouldn’t be that difficult.

    
    // somewhere in the loop on the single location page
    $town = get_field('town');
    $county = get_field('county', $town->ID);
    $state = get_field('state', $county->ID);
    

    You can also display all the towns on the single state page. You’d need to do a query of all of the county posts with a meta_query for the state, then a query of all the town posts with a meta query for the county and then finally a query of all location posts with a meta query for the county.

    I personally think you’re going about this in the right way. The only other choice would be to select the towns when editing the county, and etc. This would make management and querying more complex. What you’re doing will take a few steps to walk through the hierarchy but it can all be done with fairly simple queries.

    The only thing that I would say is that you look into using some type of object caching, possibly with the WP transients in order to keep the queries from slowing down your site.