Taxonomy Image on Custom Post Type

Support MB Term Meta Taxonomy Image on Custom Post TypeResolved

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #29136
    uptwouptwo
    Participant

    Hey,
    I need your help.
    First of all about the structure:

    CPT = press
    Taxonomy for this cpt (Hierarchical) = publisher
    Taxonomy Single Image Custom field = publisher_image

    I am trying to get the corresponding taxonomy image in each of these posts. I know you guys have the appropriate documentation for this but I can't for the life of me get it to work. Is it possible for you guys to provide me with some code that I can work with?

    Thank you in advance

    #29145
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Thank you for getting in touch.

    I think you can do it on your own with a few lines of code. Follow the guidelines
    - Get post terms: https://developer.wordpress.org/reference/functions/get_the_terms/
    - Get term meta base on the term ID: https://docs.metabox.io/extensions/mb-term-meta/#getting-field-value

    #29150
    uptwouptwo
    Participant

    Thank you for your quick response! As i wrote, i know you have the appropriate documentation for this and i'm sure that is an easy task, but i can't get it to work.

    Could you be so friendly and provide me a few lines of code?

    #29163
    Long NguyenLong Nguyen
    Moderator

    Hi,

    In the template of the single post type, you can add this code to show the image of the taxonomy

    $terms = get_the_terms( get_queried_object_id(), 'publisher' );
    foreach ( $terms as $term ) {
        $term_image = rwmb_meta( 'publisher_image', ['object_type' => 'term'], $term->term_id );
        if( is_array( $term_image ) ) {
            echo '<img src="'. $term_image['full_url'] .'">'; 
        }
    }
    #29182
    uptwouptwo
    Participant

    Awesome, thank you very much! This can be closed.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.