I have created a custom post type called "Single Neighborhood" in it i have 5 custom fields:

  1. Background Color (color picker)
  2. Background Image (image upload)
  3. Latest news (WYSIWYG editor to list external links to news)
  4. Local Events (WYSIWYG to display other RSS feeds)
  5. Listings (WYSIWYG to write out a custom paragraph)
  6. Taxonomy menu (to select a custom neighborhood like "Adams Morgan")

All of these fields will be in different divs throughout the template page so would it be best to just insert all the divs within the "while" loop and just use on loop or would multiple loops be better?

Finally how do i reference a taxonomy in the query? I mean i'm using the same Single-neighborhood template for 27 neighborhoods but i can't reference just one taxonomy within the template because then it would just pull the content for that one neighborhood, is there a dynamic way for WordPress to know what content from which neighborhood to pull by use of what link the user came in from?

I've been dealing with this issue for 4 days now and i can't seem to understand the best approach to take.

Will accomplishing something like this require custom functions, conditions within the loop to work it out?

If anyone has for example made a real estate site or a site with hierarchical structure of Neighborhoods > Neighborhood > Places > Place > Sub pages of that place that required custom content for (in the same location of each page) specific pages please advise.


  • I should also add that in addition to creating a Single-Neighborhoods custom post type I still had to create the Neighborhood Page itself so that i could apply the right template to it, but what i can't figure out is how to connect the page to the custom fields and have them all called together in the Single-Neighborhood template. I'm so close but just can't figure out a good way to bring them all together. Thanks.
    – MARS
    Commented Sep 24, 2013 at 22:04
  • 1
    I dind't understand your second question "how do i reference a taxonomy in the query?". What exactly are you trying to achive? Commented Sep 24, 2013 at 22:15
  • It seems like the very last paragraph is the "question" but there isn't a lot of detail.
    – s_ha_dum
    Commented Sep 24, 2013 at 23:03
  • @DanȘtefancu i may have it wrong, and probably do, but i've created post within a custom post type of "Neighborhoods" so each post has a different name and content. What i though would be the logical approach is to somehow on my Single-Neighborhood.php page create a query that would pull content based on taxonomy, that may very well be the wrong approach, but i can't seem to understand how WordPress will know which content to display on the Single-Neighborhood page when i'm calling content from specific custom fields for specific pages?
    – MARS
    Commented Sep 25, 2013 at 13:21
  • @s_ha_dum, you've helped me on other questions and i'm just trying to figure out how to display the custom content for a specific post on a Single-Neighborhood template? That part alludes me. I have 27 posts made within the CPT of "Neighborhood" but when i call the "the_field()" within the Single-Neigh page i only get content from one of my 27 posts that i created so this begs the question, at least for me, of how do i get WordPress to know which pages content to display on the Single-Neigh page? So my instinct was to reference taxonomies but i'm not sure that would be good in my case.
    – MARS
    Commented Sep 25, 2013 at 13:24

2 Answers 2


On your custom post type's single page, you want to treat it similar to your standard post single template. For the most part, you should wrap everything in your single template in one loop like so:

<? get_header(); ?>
    <? if(have_posts()): while(have_posts()): the_post(); ?>

    <!--Your content goes here-->

    <? endwhile; endif; ?>
<? get_footer(); ?>

As far as custom taxonomies are concerned, you may want to look into custom taxonomy page templates: http://codex.wordpress.org/Template_Hierarchy#Custom_Taxonomies_display

You can make a template like taxonomy-neighborhood.php, and then include the loop and all functions necessary to display all your listings in each neighborhood. This template will then automatically display whatever neighborhood was queried, allowing you to link directly to pages like yoursite.com/compton or yoursite.com/brooklyn. This functionality is very similar to how your single page is used to display any house.

  • that is great to know about the one loop, and the other advice is interesting, however i'm wondering if i already have a page with all my Neighborhoods listed as links to their pages (I just need to link them to the page) and this list was not created as a Menu in the admin so i have to manually insert the links to the page my question is more along the lines of linking to a specific Neighborhood and having that content for that neighborhood show up, that's my problem. I'm not really trying to show a dynamically generated list of neighborhoods but rather a fixed list.
    – MARS
    Commented Sep 25, 2013 at 13:28
  • I'm using the Advanced Custom Fields plugin with the Custom Post Type UI plugin and i what i did was create a CPT called "Single Neighborhoods" where i could create my neighborhoods individually and put their custom content there. I also created a CPT called "Neighborhood" where i could add new neighborhoods to an ongoing list. Those neighborhoods when clicked would take the user to the page of that specific neighborhood (single-neighborhood.php) but that's where i fail because i don't understand how to make the content for the specific neighborhood be called? That's my entire dilemma.
    – MARS
    Commented Sep 25, 2013 at 13:33
  • If the links that point to your "single-neighborhood.php" template are coded by you, you might look into appending a query variable to the URL like ?nhood=*your-neighborhood*. Then on your single page, you can parse this query var using php and display different content depending on the var. Or you could look into putting your neighborhoods into a custom taxonomy instead of a CPT. This would be a more elegant way of handling it if you don't need to put in a ton of info about your neighborhood. Commented Sep 26, 2013 at 1:54
  • @TSD that's interesting i'll look into that. I simplified my CPT however and i've used the get_permalink(); on my neighborhood links that lead to the pages and they still only display the custom fields from the latest neighborhood that i add as a new post. For example i add 3 neighborhoods with custom content for each of their fields, but when i go to any of the neighborhood pages it posts the same content, the same background color, etc as the first post that i made, so in this case using permalink would i still have to parse data? Or maybe add a taxonomy to the page itself in addtion to post
    – MARS
    Commented Sep 26, 2013 at 13:31
  • I think I still misunderstood you when I wrote this. Try using the archive-neighborhood template to achieve what you want. I think this may help you. Commented Sep 26, 2013 at 13:34

Here is the template i created for my main Neighborhood page that would link to all the other neighborhoods on the site. You may ask why didn't i just make a drop down nav? Too many neighborhoods to include.

What i believe i did was called all the posts for this custom post type dynamically on the page so that in the future new neighborhoods could be added.

What i failed miserably at was finding a way to add new neighborhoods to the list and sort them from the back end so i had to add my neighborhoods alphabetically in descending order. Meaning if i tried to enter new neighborhoods from A-Z neighborhoods with "A" would be at the bottom of the list and "Z" at the top (I tried the order=ASC) within my template page and it had no effect, not sure why yet.

Needless to say i entered my neighborhoods in reverse alphabetical order, i know, pretty weak. But hey it works!



  Template Name: Neighborhoods Main Page


get_header( 'internal' );?>

<div class="container-space"></div>

<div class="container-main">


  $args = array(
    'post_type' => 'neighborhood'

  $the_query = new WP_Query( $args );


  <ol class="col-neigh-title neighborhood">

  <?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

    <li><a href="<?php the_permalink(); ?>"><?php the_field( 'neighborhood_name' ); ?></a></li>

  <?php endwhile; else: ?>


  <p>There are no posts or pages here.</p>

<?php endif; ?>


<?php get_footer(); ?>

Then in my single-neighborhood.php page i did it like this:

<?php get_header( 'neighborhood' );?>


    $bg = get_field( 'bg_img' );


  <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    <div class="bg-img-default" style="background-image: url(<?=$bg?>); "></div>

    <div class="container-main">

      <!--COL 1-->

      <div class="col-block">

        <h2><span class="bold">latest</span> <span class="font-condensed">news</span></h2>

        <?php the_field( 'latest_news' ); ?>


      <!--COL 2-->

      <div class="col-block">

        <h2><span class="bold">local</span> <span class="font-condensed">events</span></h2>

        <?php the_field( 'local_events' ); ?>


      <!--COL 3-->

      <div class="col-block-last">

        <h2><span class="bold">listings</span></h2>

        <?php the_field( 'listings' ); ?>

        <a href="/search-listings/">Search Listings</a>


  <?php endwhile; endif; ?>

  <?php get_template_part( 'content', 'slider' ); ?>


<?php get_footer(); ?>

Note to noobs: The initial error in my ways was that i assumed that single type posts (of any category really "Neighborhoods", "Cities", "Cars" , "Operating Systems") also needed to be templates and that i would have to create a "Page" for each neighborhood (in my case), assign it a template to render the page differently and then link to that page from my main Neighborhoods page and some how hope it would know to grab that custom content from the post type, i know pretty foolish.

Another break through, in my understanding at least, was that you can add all of the fields associated with a neighborhood in one Custom Post type and call them from different templates. Meaning, in my case the "Name" "Background Image" "Background Color" "Content column1" "Content Col2", etc can all be entered from the user on the backend from one place but you can then call different pieces of that content within different templates. So in my example above i called the "neighborhood_name" custom field for one page (which linked to the single neighborhood) and then the remaining content was included in the single-neighborhood page. This may be a no-brainer to many people here but it was a highlight of my week:) when i discovered it.

WordPress it appears doesn't work that way and instead you create all of your custom content by creating a new Post of your Post Type and NOT by creating a new page. This made me realize there is no need to create a template that can be called on by a single neighborhood page, but rather a single-neighborhoods template that would render the single version of that post, that the user would arrive to through the permalink(), and would then grab its unique content from the post. It took me 7 days to figure this out btw.

If anyone has a cooler more advanced way to do this please share, because my near future question (which i'll link to from here when i write it) will be on how i can create a "Places" CPT that once i get into a specific neighborhood i can then click on a "Places" link from a custom sub-menu (controlled through the appearance>menus panel) and be taken to a list of places within that neighborhood that will also have it's own template rendering its look (it will look just like the neighborhoods template though).

One thing's for sure i know i won't be creating Pages (and assigning them templates) for each of these places i'll create.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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