Display taxonomy custom field (color)
Support › MB Term Meta › Display taxonomy custom field (color)
- This topic has 4 replies, 2 voices, and was last updated 2 years ago by
Peter.
-
AuthorPosts
-
March 8, 2023 at 3:42 PM #40884
Bogdan Michitele
ParticipantHello,
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,
BogdanMarch 8, 2023 at 6:35 PM #40890Peter
ModeratorHello,
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/March 10, 2023 at 2:49 PM #40934Bogdan Michitele
ParticipantHi Peter,
Thanks for the info. I will check and get back to this topic in case I stumble on anything.
All the best,
BogdanMarch 20, 2023 at 9:51 PM #41125Bogdan Michitele
ParticipantHi,
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
March 21, 2023 at 7:46 PM #41149Peter
ModeratorHello,
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 codepost.ID
to get the current post ID and pass it to theget_terms()
function to get the terms of the current post. -
AuthorPosts
- You must be logged in to reply to this topic.