Do you need to add custom meta fields to custom taxonomies in WordPress?
Custom taxonomies let you organize your content beyond categories and tags. Sometimes it’s useful to add additional fields to describe them.
In this article, we’ll show you how to add additional meta fields to the taxonomies they create.
When Should You Add Custom Meta Fields to a Custom Taxonomy?
Some websites benefit from the use of custom taxonomies. These allow you to sort your content in additional ways.
For example, a website that posts book reviews could add the taxonomies ‘Subjects’ and ‘Authors’ so that visitors can quickly find the reviews they are interested in.
For more information, see our guide on how to create custom taxonomies in WordPress.
Each taxonomy has only three or four fields by default: name, slug, parent (if it is hierarchical), and description.
Sometimes it’s useful to add additional fields to better describe the taxonomy. For example, you might add a ‘year of birth’ field to an ‘authors’ taxonomy.
With that being said, here’s how to add custom meta fields to custom taxonomies in WordPress.
Adding Custom Meta Fields to Custom Taxonomies in WordPress
Next, head over to the Custom Fields » Add New page. Here you can add a field group that contains one or more new fields.
You will be asked to give the field group a title, and this will be displayed along with the new fields when adding or editing the taxonomy. In this tutorial, we want to add a custom field to the Authors taxonomy, so we’ll name the field group ‘Author Details’.
Once you’ve done that, you should click on the ‘+ Add Field’ button to add a field. A new form will appear where you can fill in the details of the new field.
Once you enter a field label, the field name will be created for you automatically, and you can edit it if you like. You will need to use the field name later in the tutorial, so make a note of it.
Now you should fill in the other details for the field, such as the field type, instructions for your authors who will be filling in the form, and whether this field is required. Other options not shown in the screenshot include default text, placeholder text, character limit, and more.
If you wish to add a second field, then you should click the ‘+ Add Field’ button and repeat the process. Otherwise, simply scroll down to the Location section.
Here you can create rules that describe where to display the new field. You should select ‘Taxonomy’ from the first drop down menu and leave the middle field as ‘is equal to’. Finally, select the correct custom taxonomy for the last field. In this tutorial, we’ll select ‘Author’.
If you want to add this field to another taxonomy, then you can click the ‘Add rule group’ button and repeat the step.
Now you should adjust any other settings on the page. We’ll simply leave the default values. Once you’re finished, you should scroll to the top of the page and click the ‘Publish’ button.
Congratulations, you successfully added a custom meta field to a custom taxonomy in WordPress. But you still have some more work to do.
Adding Data to the New Custom Meta Field
While the taxonomy has a new field, it doesn’t yet contain any data. You should take some time to do that now.
In our example, we need to enter the year of birth for each author. To do that, we need to navigate to Posts » Authors and click on the name of the author we wish to edit.
After that, we can enter data into the new field. In this case, we will enter the year of birth for that author. Don’t forget to click the ‘Update’ button to store the new data.
You should follow the same steps on your website to add data to your custom taxonomy.
When you’ve finished, there’s still one step to go. While you can see the custom field when logged in to your WordPress admin area, visitors to your website will not be able to see it. You will need to add the field to the custom taxonomy’s archive page.
Displaying a Custom Meta Field on Your Taxonomy Archive Page
In this step, you’ll need to add code to your theme files. If you haven’t done that before, then refer to our beginner’s guide on how to paste snippets from the web into WordPress.
The first thing you need to do is go inside your theme’s folder and look for your taxonomy archive file. It will have a name like
For example, if you have a custom taxonomy called ‘authors’, then you need to look for a file called
If you don’t see that file, then look for
archive.php. You will need to make a duplicate of that file and name it as described above.
Note: If your theme doesn’t include archive.php, then you’re probably using a WordPress theme framework and will have to create the taxonomy archive manually. A good starting point for learning how to create archive files is our guide on how to create custom archive pages in WordPress.
Now you need to add the following code to the taxonomy archive right before the loop:
<?php // get the current taxonomy term $term = get_queried_object(); // get the taxonomy meta field $taxonomymetafield = get_field('FIELDNAME', $term); // display the taxonomy meta field echo $taxonomymetafield; ?>
Note that you need to replace ‘FIELDNAME’ with the actual field name you created above. Remember, we asked you to make a note of it.
In our example, the field name is ‘year_of_birth’. We’ll also add a description so our visitors understand what the field means. So we’ll add the following code to the taxonomy archive file
<?php // get the current taxonomy term $term = get_queried_object(); // get the taxonomy meta field $taxonomymetafield = get_field('year_of_birth', $term); // display the taxonomy meta field echo "Year of birth: "; echo $taxonomymetafield; ?>
Here’s how it looks on our demo site.
We hope this tutorial helped you learn how to add custom meta fields to custom taxonomies in WordPress. You may also want to learn how to add keywords and meta description in WordPress, or check out our list of must have plugins to grow your site.