1

i add some custom meta field to product taxonomy "artist" they work well and save to taxonomy

    /**
add meta data to artist taxonomy */

function artist_add_meta_fields( $taxonomy ) {
    ?>
    <div class="form-field term-group">
        <label for="artist_nickname"><?php _e( 'Nickname', 'my-plugin' ); ?></label>
        <input type="text" id="artist_nickname" name="artist_nickname" />
    </div>

    <?php
}
add_action( 'artist_add_form_fields', 'artist_add_meta_fields', 10, 2 );


function artist_edit_meta_fields( $term, $taxonomy ) {
    $artist_nickname = get_term_meta( $term->term_id, 'artist_nickname', true );
     ?>

    <tr class="form-field term-group-wrap">
        <th scope="row">
            <label for="artist_nickname"><?php _e( 'Nickname', 'my-plugin' ); ?></label>
        </th>
        <td>
            <input type="text" id="artist_nickname" name="artist_nickname" value="<?php echo $artist_nickname; ?>" />
        </td>
    </tr>

    <?php
}
add_action( 'artist_edit_form_fields', 'artist_edit_meta_fields', 10, 2 );

function artist_save_taxonomy_meta( $term_id, $tag_id ) {
    if( isset( $_POST['artist_nickname'] ) ) {
        update_term_meta( $term_id, 'artist_nickname', esc_attr( $_POST['artist_nickname'] ) );
    }

}
add_action( 'created_artist', 'artist_save_taxonomy_meta', 10, 2 );
add_action( 'edited_artist', 'artist_save_taxonomy_meta', 10, 2 );

but i cant get them in taxonomy-artist.php in frontend

//Get Taxonomy Meta
$artist_nickname = get_term_meta($term->term_id,'artist_nickname');
echo $artist_nickname; 

but nothing displayed. where is my problem?

1

If you want to display in archive or category (taxonomy) template, try this:

$artist_nickname = get_term_meta( get_queried_object_id(), 'artist_nickname', true);
echo $artist_nickname;
  • thanks its working . can i insert a conditional show item? if the term exist show the term – Muhama MHM Nov 16 '17 at 9:49
  • how i can image taxonomy in archive template? – Muhama MHM Nov 17 '17 at 12:52
0

You can use this

$youvaribale = get_term_meta( get_queried_object_id(), 'fieldname', true);

OR

$youvaribale = get_term_meta( catid, 'fieldname', true);

echo $youvaribale;
  • how i can get image taxonomy? – Muhama MHM Nov 17 '17 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.