Skip Navigation

[Resolved] I want to display ONLY the STATES that have LISTINGS

This support ticket is created 4 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 5 replies, has 2 voices.

Last updated by Christian Cox 4 years, 10 months ago.

Assisted by: Christian Cox.

Author
Posts
#1285443

Ed

I have a directory, with STATES, COUNTIES, CITIES, and LOCATIONS.

Each COUNTY belongs to a STATE.

Each City belongs to a COUNTY in a STATE.

Each LOCATION belongs to a STATE, a COUNTY, and a CITY.

On the page displaying the list of STATES, I only want to display the STATES that have LOCATIONS.

Is that possible, without too much trouble?

#1285693

Is that possible, without too much trouble?
It's possible, but it's fairly complex because there is no Query Filter to filter by whether or not a post has a great-grandchild post in a specific post type. Here's how it could be set up without custom PHP code:
- Create a View of Locations without any filters.
- Use the Loop Wizard to create a "List with separators" design.
- In the Loop, insert a Content Template using the "item" attribute and "@relationship-slug.parent" syntax to switch the context to the City context. Inside that Content Template, insert another nested Content Template using the item attribute and "@relationship-slug.parent" syntax to switch context to the County context. Nest another Content Template using the item attribute and the "@relationship-slug.parent" syntax to switch context to the great-grandparent State. We have documentation about using Content Template nesting to achieve context switching: https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/displaying-fields-of-grandparents/
- In the great-grandparent (State) context, insert the wpv-post-id shortcode to display the State post ID.
- Check the "disable the wrapping Div" checkbox in the View editor
- This should produce a comma-separated list of State post IDs on the front-end of the site, something like this:
1, 2, 3, 4, 5
- There may be duplicates in this list. That's okay.
- Create one more View of State posts and add a post ID Query Filter, where the post ID is set by one shortcode attribute "ids".
- Use the Loop Wizard to design your list of State posts.
- Insert this View shortcode in your site and insert the View of Locations as the value of the "ids" attribute. The shortcodes will look something like this:

[wpv-view name="your-view-of-states" ids="[wpv-view name='your-view-of-locations']"]

Now the comma-separated list of State IDs created by the View of Locations is feeding the post ID filter of the View of States.

#1285799

Ed

Let's make it simpler (I hope)...

Can I display only the STATES which have existing children that are the LOCATION post type (LOCATIONS as children)? Is that any easier?

All STATES will have children of the COUNTY and CITY post types, but I don't want the STATE to be displayed, if it doesn't have any LOCATIONS (which also belong to CITIES and COUNTIES).

Thanks for your help with this.

#1286439

The process is identical, but there will be fewer nested Content Templates required to switch the context to State posts.

Or, you could create a View of child Locations and in the loop you can display information about the parent State. However, this will result in duplicate States showing in the list.

#1287747

Ed

Christian,
It may take me some time to implement this solution. You can go ahead and mark this as resolved. I can come back to it or start a new ticket, if needed.

Thank you so much!

#1287761

Sure, feel free to reopen or start a new thread.

This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.