WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. EliCash2
    Member
    Posted 4 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
    Member
    Posted 4 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>
    	<td>
        <select name='category_theme' id='category_theme'>
    	<option class='theme-option' value='one'>One</option>
    	</select>
    	 </td>
    </tr>
    
    <?php
    }
  3. EliCash2
    Member
    Posted 4 years ago #

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

  4. EliCash2
    Member
    Posted 4 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
    Member
    Posted 4 years ago #

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

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

    http://adambrown.info/p/wp_hooks/hook/edit_%7B$taxonomy%7D_%7B$field%7D

  6. EliCash2
    Member
    Posted 4 years ago #

    Is this even the right tag? Anyone?

  7. avgeneral
    Member
    Posted 4 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