Display Taxonomy Link from metabox

Support General Display Taxonomy Link from metabox

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #13268
    Vee JayVee Jay
    Participant

    I followed the documentation and was able to create several custom post types, custom taxonomies and to add metaboxes to my post type.

    One of the field i'm using is taxonomy.
    I'm able to display the taxonomy on my post, but it doesn't link to anything.

    Here's my code:

    $ptf = rwmb_meta( 'pub_type_field' );
    echo $ptf->name;

    What would be the normal way to display both the name of the taxonomy and the link to the archive page of the said tax? Thanks

    #13289
    Anh TranAnh Tran
    Keymaster

    Hi Vee Jay,

    The rwmb_meta returns a term object, so if you echo $ptf->name, you output only its name.

    It's better to use:

    rwmb_the_value( 'pub_type_field' );

    Or:

    $ptf = rwmb_meta( 'pub_type_field' );
    printf( '<a href="%s">%s</a>', get_term_link( $ptf ), $ptf->name );
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.