Skip to main content
Updated answer to include more details instead of just a link
Source Link
Jay
  • 101
  • 1

Here is an example of addingWordpress allows you to add Meta to Categories using a plugin:

To do this you need to add one of the various extensions that adds meta to categories (mimicking what pages get out of the box), Simple Term Meta does the job nicely.

N.B. WordPress 3.x is needed for extending Categories.

After that you can styleuse:

  • add_term_meta
  • update_term_meta
  • get_term_meta

Use Functions.php to add methods to do what you want e.g.

add_action('category_add_form_fields', 'category_metabox_add', 10, 1);

function category_metabox_add($tag) { ?>
    <div class="form-field">
        <label for="image-url"><?php _e('Image URL') ?></label>
        <input name="image-url" id="image-url" type="text" value="" size="40" aria-required="true" />
        <p class="description"><?php _e('This image will be the thumbnail shown on the category page.'); ?></p>
    </div>
<?php } 

add_action('created_category', 'save_category_metadata', 10, 1);

function save_category_metadata($term_id)
{
    if (isset($_POST['image-url'])) 
        update_term_meta( $term_id, 'image-url', $_POST['image-url']);                  
}

Calling new fields in themes is easy:

<?php echo get_term_meta(get_query_var('cat'), 'image-url', true); ?>

More details and choose the input type examples: http://www.wphub.com/adding-metadata-taxonomy-terms/

Here is an example of adding Meta to Categories, you can style and choose the input type http://www.wphub.com/adding-metadata-taxonomy-terms/

Wordpress allows you to add Meta to Categories using a plugin:

To do this you need to add one of the various extensions that adds meta to categories (mimicking what pages get out of the box), Simple Term Meta does the job nicely.

N.B. WordPress 3.x is needed for extending Categories.

After that you can use:

  • add_term_meta
  • update_term_meta
  • get_term_meta

Use Functions.php to add methods to do what you want e.g.

add_action('category_add_form_fields', 'category_metabox_add', 10, 1);

function category_metabox_add($tag) { ?>
    <div class="form-field">
        <label for="image-url"><?php _e('Image URL') ?></label>
        <input name="image-url" id="image-url" type="text" value="" size="40" aria-required="true" />
        <p class="description"><?php _e('This image will be the thumbnail shown on the category page.'); ?></p>
    </div>
<?php } 

add_action('created_category', 'save_category_metadata', 10, 1);

function save_category_metadata($term_id)
{
    if (isset($_POST['image-url'])) 
        update_term_meta( $term_id, 'image-url', $_POST['image-url']);                  
}

Calling new fields in themes is easy:

<?php echo get_term_meta(get_query_var('cat'), 'image-url', true); ?>

More details and examples: http://www.wphub.com/adding-metadata-taxonomy-terms/

Source Link
Jay
  • 101
  • 1

Here is an example of adding Meta to Categories, you can style and choose the input type http://www.wphub.com/adding-metadata-taxonomy-terms/