Family Encyclopedia >> Electronics

How to Add Custom Meta Fields to WordPress Custom Taxonomies: Developer Guide

By default, WordPress taxonomies like categories and tags offer fields for name, slug, parent, and description. On a recent client project, our experienced development team needed to add custom meta fields to a custom taxonomy for displaying unique text on each archive page. Hardcoding content via conditional statements in the taxonomy-{name}.php template was inefficient and limited client control. Instead, we implemented custom meta fields for flexible, future-proof management.

In this practical guide, we'll walk you through our streamlined solution using a community-vetted class. Note: This tutorial is for developers and designers with PHP experience.

After reviewing Pippin's solid tutorial, we sought a more efficient approach—ideally a plugin or reusable class. Enter Ohad Raz's Taxonomy Meta Class on GitHub. Ohad developed it to solve the same challenge, making it accessible for everyone. Kudos to this WordPress community hero.

For reusability across sites, we created this as a plugin (it works in themes too). Follow these steps:

Download the class from GitHub. Create a new folder named "taxonomy-fields" and place the "Tax-meta-class" folder inside it.

The zip includes class-use-demo.php. Rename it to taxonomy-fields.php.

Ohad's documentation shines, with ready examples for text fields, textareas, checkboxes, selects, radios, dates, times, color pickers, file uploads, and more. Edit to include only what you need.

Upload the "taxonomy-fields" folder to /wp-content/plugins/. Activate the plugin, then populate your fields from the taxonomy edit screens.

Now display the data in your taxonomy template (e.g., taxonomy-{taxonomy}.php):

<?php $saved_data = get_taxonomy_meta( $term->term_id, 'text_field_id' ); echo $saved_data; ?>

Simple, effective, and workflow-boosting. We've deployed this on multiple client sites with great results. This method enhances your WordPress development efficiency.