Additional field on Custom Post Type's Taxonomy (7 posts)

  1. EliCash2
    Posted 6 years ago #

    Complicated to explain, hang in here.

    I've created a Custom Post Type. That Custom Post Type has a taxonomy I created (the "tags" kind). On the "Edit" page in the WordPress UI for a single tag in that taxonomy, I want to be able to add additional fields that users can enter in (and display them on the template page).

    Thoughts on how I would go about doing this? Thanks.

  2. EliCash2
    Posted 6 years ago #

    I've now figured out how to add a field to ALL tags, including the taxonomy I created. But how do I make it only apply to a single taxonomy associated with a single Custom Post Type?

    Here's the code I've got so far in functions.php:

    add_action ( 'edit_tag_form_fields', 'your_input_box');
    function your_input_box($tag) {
    	// Get all themes - the hide_empty argument enables you to get all the terms in your 'theme' taxonomy even the empty ones
    	$themes = get_terms('theme', 'hide_empty=0'); 
    <tr class="form-field">
    	<th scope="row" valign="top"><label for="category_theme"><?php _e('Additional Tag Field') ?></label></th>
        <select name='category_theme' id='category_theme'>
    	<option class='theme-option' value='one'>One</option>
  3. EliCash2
    Posted 6 years ago #

    Hmm... is it maybe possible to do this with an If statement?

  4. EliCash2
    Posted 6 years ago #

    Please. Anyone. I'm begging. How do I get it to ONLY apply to this single taxonomy on this single Post Type?

  5. EliCash2
    Posted 6 years ago #

    I've now discovered edit_{$taxonomy}_{$field}

    But I can't figure out how to implement it. Please help?


  6. EliCash2
    Posted 6 years ago #

    Is this even the right tag? Anyone?

  7. avgeneral
    Posted 6 years ago #

    instead of using get_terms() which retrieves ALL terms, use this instead:

    $theme = get_the_terms($post->ID, 'theme');

    $theme is of type Array()

    in order to get the value, use this:

    echo $theme[0]->name;

Topic Closed

This topic has been closed to new replies.

About this Topic