Display taxonomy custom field (color)

Support MB Term Meta Display taxonomy custom field (color)

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #40884
    Bogdan MichiteleBogdan Michitele
    Participant

    Hello,

    I have a taxonomy on a CPT for which I created a custom field, which allows users to select a color for that term.

    What I'm struggling with is displaying this in the Elementor template for that CPT. I read a bit in the documentation and the support forums, and based on that I'm guessing this is something where Views would be used.

    However, I'm not sure how to approach adding the color next to the taxonomy term. I'm also a beginner at MetaBox and Views, so I might need a bit of help with this 🙂

    How could I use that custom field to set the background color of a div for example? I am trying to create a shortcode for this, so that I can than add it in the Elementor template.

    Please let me know if any extra information is needed.

    Thank you and all the best,
    Bogdan

    #40890
    PeterPeter
    Moderator

    Hello,

    To use the shortcode in the Elementor builder, you need to create your own code in View to get the field value and HTML elements. You can refer to this tutorial https://docs.metabox.io/tutorials/category-thumbnails/

    and read more on the documentation https://docs.metabox.io/extensions/mb-views/
    https://docs.metabox.io/extensions/mb-term-meta/

    #40934
    Bogdan MichiteleBogdan Michitele
    Participant

    Hi Peter,

    Thanks for the info. I will check and get back to this topic in case I stumble on anything.

    All the best,
    Bogdan

    #41125
    Bogdan MichiteleBogdan Michitele
    Participant

    Hi,

    i created a view shortcode with this (started from below example but with my data)

    {% set args = {hide_empty: 1, type: post, taxonomy: organizatoreveniment} %}
    {% set events = mb.get_categories( args ) %}
    <div class="thumbnail-images">
        {% for event in events %}
            <div class="item">
                <div class="overlay-thumbnail-categories"></div>
                <div class="category-title">{{ event.name }}</div>
        {% set image_url = mb.get_term_meta( event.term_id, 'url_images_category', true ) %}
        {% if image_url %}
            <img src="{{ image_url }}" />
        {% endif %}
            </div>
    {% endfor %}
    </div>

    where my custom post type is "eveniment" and my custom taxonomy for this CPT is "orzanizatoreveniment", but this shows me in single post page all website terms or something. I want to show in single post page just specific post taxonomy term and her image. In this case is that https://nimb.ws/twyO2H

    here is my CPT with custom taxonomy for him and term with title and image https://nimb.ws/wTEc1K

    i need to change the structure for your code ? to show only specific term and image for specific CPT in single psot page

    thanks <3

    #41149
    PeterPeter
    Moderator

    Hello,

    orzanizatoreveniment is a custom taxonomy so you need to use the function get_terms() to get the terms of the custom taxonomy.
    And if you assign the view to the single post type, you can use code post.ID to get the current post ID and pass it to the get_terms() function to get the terms of the current post.

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