There are multiple areas of WordPress which generate URLs to access content on your WordPress website. However, in this article, I’ll just be touching base on the commonly and widely used Object Types used on a variety of WordPress websites.

These types of objects are a nice way to organize and split up the content on your website. The possibilities are endless once you get a better understanding of what each of these objects are, and what what they can be used for.

WordPress Content Organization Objects

There are essentially four main types of objects which are very commonly used throughout a WordPress website: Post Type Objects, Post Objects, Taxonomy Objects, and Term Objects.

  1. Post Type Objects

    Post Type Objects are intended to consist of multiple Post Objects. The main purpose of a Post Type Object is to classify the type of information in a particular section of your website. Post Type Objects are usually topic based and are used to broadcast bits of information relevant to the general/overall topic.

    Post Type Archives  could be used to refer to the Post Type Object’s purpose. Post Type Archives serve as a “central hub” for all Post Objects within a particular Post Type. An example of a Post Type Object is “Posts” or “Pages”.

    Post Types (like Taxonomies) can also be “flat” or “hierarchical”. An example of a “flat” Post Type would be “Posts”, since you can only create a top-level Post Object. An example of a “hierarchical” Post Type would be “Pages”, since you can create sub-pages.

  2. Post Objects

    Post Objects can be referred to as the individual posts within a Post Type Archive. Post Objects can serve multiple purposes. However, they tend to be the “central hub” for all the types of objects used throughout WordPress. A good example of this is a blog article. Every article you write is a Post Object, associated with the Post Type of “Post”. Another example would be every page that you create is a Post Object associated with the Post Type of “Page”.

    Post Objects connect all areas of your website. This is almost always going to be the main source of information which links out to other areas of your WordPress website. Another example might be a blog article. Linking out to several other objects like Taxonomies, Authors, Archives, and even other Post Objects.

  3. Taxonomy Objects

    Taxonomy Objects intended to consist of multiple Term Objects. The main purpose of a Taxonomy Object is to classify the type of information within one and/or multiple Post Type Objects. Much like Post Type Objects, Taxonomy Objects are usually topic based and are used to broadcast bits of information relevant to the general/overall topic within one or more Post Type Objects.

    Taxonomies can be thought of as a “sub-topic” of the “main topic” which would be referred to as the Post Type Object. Taxonomy Objects are commonly used to create relevancy between Post Type Objects. However, they can also be specifically to one Post Type Object by sub-classifying Singular Post Objects within a Post Type Object, by assigning a Term Object.

    Taxonomy Archives serve as a “central hub” for all Term Objects within a particular Taxonomy. An example of a Taxonomy Object would be hierarchical “Categories” or flat “Tags”. Hierarchical Taxonomy Objects mean they can have multiple Term Objects with the possibility of descendant Term Objects. Flat Taxonomy Objects can only have one level of Term Objects with no parent/child relationship. Taxonomies Objects can help to connect multiple Post Type Objects together.

  4. Term Objects

    Term Objects are intended to consist of multiple Post Objects which have been assigned to a specific Term Object within a specific Taxonomy Object. The main purpose of a Term Object is to classify the type of information within one and/or multiple Taxonomy Objects.

    Terms are usually topic based and are used to broadcast bits of information relevant to the general/overall topic within one or more Taxonomy Objects. To clarify this a bit more. The Post Type Object would be the main topic. The Taxonomy Object would be a sub-topic of the main topic. The Term Object would be like a sub-sub-topic.

    Term Archives serve as a “central hub” for relevant Post Objects. An example of a Term Object would be a specific “Category” in the “Categories” Taxonomy or a Specific “Tag” in the “Tags” Taxonomy. Term Objects can help to connect multiple Post Objects together. Categories are like a broad grouping of Post Objects and Tags are typically a more specific grouping of Post Objects.

Another important content organizational object would be User Objects. However, that’s a completely different can of worms. We’ll save that topic for another day. Perhaps when/if I ever get a craving for sugar coated gummy worms.

Summary of Object Types

Just to give a quick recap on the common types of objects used in WordPress:

  • Post Type Objects are the Parent Topics.
    — Post Type Objects are the home of all Singular Post Objects.
  • Taxonomy Objects are the Child Topics.
    — Taxonomy Objects provide commonality between Post Type Objects and Term Objects. Taxonomy Objects are useless without Term Objects.
  • Term Objects are the Grandchild Topics.
    — Term Objects are used to group Singular Post Objects. Term Objects require Taxonomy Objects.

WordPress Template for Post Type with Nested Taxonomy

By default, in my opinion, WordPress refers to the “Taxonomy Archive” as more of a “Term Archive”. I wrote an article about modifying the default archive behavior of the WordPress template system.

I’m a believer in all URL segments resolving to display appropriate (and hopefully not duplicate) content. What I mean by that is, make sure that each of your “archive templates” serve different content.

Essentially what that article teaches you is: How to add taxonomy.php and term.php to your WordPress theme.

  • taxonomy.php is a Taxonomy Archive intended to consist of multiple Term Objects assigned to the current Taxonomy Object.
  • term.php is a Term Archive intended to consist of multiple Post Objects assigned to the current Term Object within a specific Taxonomy Object.

In this article, I’ll teach you how to setup a URL structure like this:
www.domain.com/<post-type-slug>/<taxonomy-slug>/<category-slug>/<post-slug>/

An example of the above URL would be like this:
www.domain.com/cars/manufacturer/honda/2017-civic/

The above URL structure allows you to have a Post Type Object which consists of multiple cars. Each car would be a specific Post Object assigned to the Post Type Object. You can then “categorize” your cars by “manufacturer”, which would be a Taxonomy Object. You can assign a car to a specific “manufacturer”, which would be a Term Object.

* Note: This scenario isn’t always applicable. You would likely want to use this scenario with a “category-like” approach, which would be a hierarchical Taxonomy and not a “tag-like” approach, which would be a “flat” Taxonomy.

* * Note: If you decide to do this. Please only assign the Post Object to ONE Term Object within ONE specific Taxonomy Object. Do not do this with multiple Term Objects or Multiple Taxonomies, within the same Post Type Object. Doing so will create duplicate content. A good idea would be to set show_gui => false when you register your Custom Taxonomy. Add your own Meta Box and list each Term Objects with a radio input field instead of a checkbox field. This will force the user to only select ONE Term Object, instead of MULTIPLE Term Objects in a given Taxonomy Object when editing the Post Object in the backend of WordPress on the Post GUI screen. For the sake of this article, I’ll just be using the default Meta Box UI which comes with the hierarchical Taxonomy type.

Let me say that just about everyone in the WordPress community would disagree with this approach to a URL structure for the exact reason of duplicate content. I’ve found this approach applicable in certain situations. Since I disagree with their opinions, I’m sharing my experience with you. Please exercise caution with this tactic. Don’t say I didn’t warn you.

Step 1 – Register The Post Type Object

Step 2 – Register The Taxonomy Object

Step 3 – Modify WordPress URL Functionality

Step 4 – Modify the Template Hierarchy

A.) Create a basic PHP class file to make this process clean and simple.

B.) Define types of registered objects, including post_types and taxonomies

C.) Generate Custom Rewrite Rules

D.) Specify Taxonomy Template Location

E.) Specify Term Template Location

 

Step 5 – Regenerate Permalink Structure

You can do this via code by calling flush_rewrite_rules(); or you can simply go to: Dashboard -> Settings -> Permalinks -> Save Changes. Either way, this will create an updated copy of all the rewrite rules. Particularly the ones created from the previous steps up to this point.

Step 6 – Create the Term Objects

You’ll want to create some Term Objects or A/K/A “manufacturers”. You can do this by going to: Dashboard -> Cars -> Manufacturers and use the form to create a new manufacturer. For an example give one a name of “Honda”.

Step 7 – Create Template Files

Essentially in Step 4, the default template hierarchy was changed a bit…

  1. If you go to domain.com/cars/manufacturer/ it loads taxonomy.php from your currently active WordPress theme directory.
  2. If you go to domain.com/cars/manufacturer/<term-slug>/ it loads term.php from your currently active WordPress theme directory.

Step 8 – Create the Post Objects

You’ll want to create some Post Objects or A/K/A the various car models. For example you would go to Dashboard -> Cars -> Add New Give it a title of “2017 Civic”.

Step 9 – Assign the Post Objects to a Term Object

While you’re adding a new car, look on the right side of the screen for the “Manufacturers” meta box. Select “Honda” from the list of manufacturers in that meta box.

Scroll up and look for the “Publish” meta box on the right side of the screen and click the blue “Publish” button to save your new car.

Conclusion

  1. When viewing domain.com/cars/ – Default archive templates are loaded as usual. (archive.php, archive-$posttype.php, etc) from your currently active WordPress theme.
  2. When viewing domain.com/cars/manufactuerr/ – The taxonomy.php template file is loaded from your currently active WordPress theme.
  3. When viewing domain.com/cars/manufacturer/<term-slug> – The term.php template file is loaded from your currently active WordPress theme.

You can easily test to see if this works. All you need is three files in your currently active WordPress theme directory.

  1. archive.php or archive-posttype.php
  2. taxonomy.php
  3. term.php

Put this in archive.php or archive-$posttype.php

Put this in taxonomy.php

Put this in term.php

This article was a follow up or updated article for: WordPress Template for Post Type with Nested Taxonomy

Related Questions

This article assists in answering all of the following related questions:

  1. [WordPress Development] How to modify URL structures in custom post types and taxonomies or terms asked by: @Michael Ecklund
  2. [WordPress Development] Custom Post Type with Nested Taxonomy and Template Files asked by: @Michael Ecklund
  3. [WordPress Development] How to completely disable a taxonomy archive on the frontend? asked by: @Michael Ecklund
  4. [WordPress Development] How to Add Pages Under Custom Post Type URL Structure? asked by: @Michael Ecklund

DISCUSSION

As always, if you found this article useful or you’d like to share your thoughts, please do so in the comments below. If there’s something that’s unclear or hard to understand, let me know and I’ll do my best to produce a clarified update to the article. THANKS FOR READING!

Leave a Reply