I am working on a site that highlights neighborhoods.

Within each neighborhood there are places (that will be added by the client on the back end).

Each neighborhood will have its own unique set of places.

I figured out how to lead a list of all neighborhoods (neighborhood.php) to it's specific single neighborhood (single-neighborhood.php).

However once i get into a single neighborhood i don't understand how to create a link to a list of places (which would be a Custom Post Type) that would then link to their single place page.

I was considering using the concept of creating a Places Custom Post Type and then a single-place.php page template but i'm wondering how WordPress would interpret that and how it would lead to the correct post.

Here is an image that shows the heirarchy, i have completed levels 1 through 3 and am trying to figure out 4-5.

Quick Map Site Structure

I know how to create Custom Post Types, I know how to make custom fields, I know how to connect the custom fields to templates.

What i don't know and am trying to figure out is how to link to the single places from a specific neighborhood?

How does wordpress understand what Place post to go to?

In Summary I:

  1. Created 27 neighborhoods
  2. Each neighborhood has a sub navigation that leads to "Places" "History" "Gallery" "Points of Interest"
  3. I need to figure out how to link a list of Places to the "Places" sub nav link and have it pull the content from a specific Place Custom post and then have that list lead to a single place page

I understand the concept of neighborhood.php template permalinking to single-neighborhood.php but i don't get how to make a further nested site heirarchy work under this logic would it still be place.php to single-place.php?

If so how do i link to a list of places relevant to specific neighborhoods within the single-neighborhood page?

Thank you.


There are three ways you can go about this:

  1. Add custom rewrite rules that will indicate which neighborhood the places templates should pull from, add logic to alter the query to only load those places, and add meta fields to link the places to a neighborhood (lots of work)
  2. Add a "Neighborhood" taxonomy for the places (has redundant data)
  3. Merge the post types into one hierarchical post type (not well organized)

Personally, I would go with (2). If you decide to go that route, it would be as simple as

  1. Register your custom taxonomy
  2. Leveraging the template hierarchy, add custom templates for your places, e.g. taxonomy-neighborhood.php

While this does have some data redundancy (individual neighborhoods will be both posts in a post type as well as terms in a taxonomy), that's rectifiable. The key to making this work well is convention over configuration: make sure that all the neighborhood slugs are identical in the post and term.

If it were me, I would then hook into the save_post process and make it so that any time a neighborhood is added or its slug edited, a term is also added or edited behind-the-scenes. I would also remove the term pages from the admin panel so the editors can't add/edit the terms, and only have access to the posts.

  • when you say add custom templates for your places, eg-taxonomy-neighborhood.php, are you suggesting i create a different template for each place? Places will be added by the client so couldn't expect them to make a template for each place. Maybe i wasn't clear but i need a dynamic list of places to be pulled (from a sub-navigation menu that each neighborhood will have) that match the neighborhood the user is currently in. So if a user goes to Neighborhood A and selects "Places" from the sub-nav within that neighborhood only places of that specific neighborhood should display. Thanks. – MARS Oct 4 '13 at 13:26
  • This is different than other ways that i see WP being used. For example there are tons of great examples on how to link to a query for a specific set of posts that belong to a certain, category, tag or taxonomy. What i don't see much of is how to link to content dynamically. All i was hoping that could be done is give the "Places" link some kind of identifier to know it's on a particular parent neighborhood page and based on that understanding when someone clicks on "Places" it could pull a list of places based on the matching taxonomy. But i haven't found one solution that supports this. – MARS Oct 4 '13 at 13:27
  • taxonomy-neighborhood.php would be the file name, and would cover all places (in the neighborhood taxonomy). You wouldn't need to create a new file for each term in the Neighborhood taxonomy. re:your second question, the issue is that there's no "core" way to indicate that one post in one custom post type is a "parent" of another post in another custom post type. That's why there's no "identifier to know it's on a particular parent neighborhood page." The taxonomy would give you that. It's best not to think of it as parent-child but as classification. – Matthew Boynes Oct 4 '13 at 13:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.