taxonomies.json

This file is responsible for registering custom taxonomies in PorterWP.

Structure

The taxonomies.json file follows a simple structure where you define your taxonomies and the associated object types (post types) that will use them.

Example

An example of a basic taxonomy definition might look like this:

{
	"version" : "1.0.0",
	"taxonomies" : {
		"archive-topic" : {
			"object_type" : [
				"post",
				"event",
				"playbook",
				"podcast",
				"research",
				"video"
			],
			"hierarchical" : true,
			"labels" : {
				"name" : "Old Topics",
				"singular_name" : "Old Topic"
			}
		}
	}
}

This defines a taxonomy called "Archive Topic," which is hierarchical (like categories), and it is attached to multiple post types including post, event, and more.

Hierarchical and Non-Hierarchical Taxonomies

Taxonomies can either be hierarchical (like WordPress categories) or non-hierarchical (like tags). The hierarchical setting determines whether the taxonomy behaves like a category (with parent-child relationships) or a tag.

For example:

  • Hierarchical (like categories)

"archive-topic" : {
	"object_type" : ["post", "event"],
	"hierarchical" : true,
	"labels" : {
		"name" : "Old Topics",
		"singular_name" : "Old Topic"
	}
}
  • Non-Hierarchical (like tags)

"topic-tag" : {
	"object_type" : ["post"],
	"hierarchical" : false,
	"labels" : {
		"name" : "Topic Tags",
		"singular_name" : "Topic Tag"
	}
}

Labels

Like post types, PorterWP will try to auto-generate labels based on the taxonomy name, but you can override the labels by specifying the labels object in your taxonomy definition.

"article-type" : {
	"object_type" : ["post"],
	"hierarchical" : true,
	"labels" : {
		"name" : "Article Types",
		"singular_name" : "Article Type"
	}
}

Object Types

The object_type field defines the post types that the taxonomy is associated with. For example, the following will associate the taxonomy event-type with the post type event:

"event-type" : {
	"object_type" : ["event"],
	"hierarchical" : true,
	"labels" : {
		"name" : "Event Types",
		"singular_name" : "Event Type"
	}
}

Register New Taxonomies

To register a new taxonomy, simply add it to the taxonomies object. For example, adding a new taxonomy called research-type:

{
	"version" : "1.0.0",
	"taxonomies" : {
		"research-type" : {
			"object_type" : ["research"],
			"hierarchical" : true,
			"labels" : {
				"name" : "Research Types",
				"singular_name" : "Research Type"
			}
		}
	}
}

This would create a taxonomy called "Research Types" that can be used for the post type research.

Modifying Supports

PorterWP also allows you to modify taxonomy support settings. If you override the default settings, remember to define all the necessary parameters as PorterWP will assume you want to set all options manually.

For example:

"video-type" : {
	"object_type" : ["video"],
	"hierarchical" : true,
	"labels" : {
		"name" : "Video Types",
		"singular_name" : "Video Type"
	}
}

Conclusion

The taxonomies.json file allows you to manage and register custom taxonomies efficiently. PorterWP simplifies the process while giving you the flexibility to adjust labels, hierarchies, and object types according to your needs.

Last updated