Impossible to display the custom field (image) of a custom term.
Support › MB Term Meta › Impossible to display the custom field (image) of a custom term.
- This topic has 6 replies, 2 voices, and was last updated 10 months, 3 weeks ago by
Peter.
-
AuthorPosts
-
May 24, 2024 at 12:36 PM #45515
pixluser
ParticipantHello,
I've tryed everything it's impossible for me to display the custom field single image, of my custom term, inside the template that display the custom post type.I'm using oxygen. But I've used php, views… nothing works.
I've followed tutorials too. Same result.I would like to display the pictures (single image) attached to my terms, inside my custom post type template.
May 24, 2024 at 12:48 PM #45516pixluser
Participanthere is the code of the tutorial :
{% set args = {taxonomy: 'portfolio-type',hide_empty: false} %} {% set portfolios = mb.get_terms( args ) %} <div class="portfolio container"> <h1 class="heading-title">Portfolio</h1> <div class="thumbnail-images"> {% for portfolio in portfolios %} <div class="item"> <div class="overlay-thumbnail-categories"> {% set image_upload = mb.get_term_meta( portfolio.term_id, 'upload_portfolio_thumbnail', true ) %} {% set image_url = mb.get_term_meta( portfolio.term_id, 'url_portfolio_thumbnail', true ) %} {% if image_upload %} {% set image_upload_link = mb.wp_get_attachment_image_src( image_upload, large) %} <div class="thumbnail" style="background-image:url({{ image_upload_link [0] }})"></div> <img src="{{ image_upload_link[0] }}"> {% elseif image_url %} <div class="thumbnail" style="background-image:url({{ image_url }})"></div> <img src="{{ image_url }}"> {% else %} <img src="http://demo1.elightup.com/test-metabox/wp-content/uploads/2020/11/oriental-tiles.png"> {% endif %} </div> <div class="category-title"> <div class="category-name">{{ portfolio.name }}</div> <p class="description"> {{ portfolio.description }} </p> <a href="{{ mb.get_category_link( portfolio.term_id ) }}" target="_blank" rel="noopener">View More</a> </div> </div> {% endfor %} </div> </div>
How to change this code to only display the 'current' category, on a custom post type template. please.
May 24, 2024 at 12:49 PM #45517pixluser
ParticipantBecause this code currently list all my terms, and not the current terms used on the custom post.
May 25, 2024 at 11:55 AM #45530Peter
ModeratorHello,
If you want to show the term meta (image) of a term on the single post page. You can try to use two WordPress functions:
- get the current post ID: get_queried_object_id()
- get terms by post ID: get_the_terms()If you are not able to complete the task, we offer a customization code with an extra fee. Please contact us here for more details https://metabox.io/contact/.
May 25, 2024 at 12:03 PM #45531pixluser
ParticipantHello Peter, thanks.
So I understand, it's not possible to do that with views? (Because I bought meta box for not doing php, as I'm not a PHP coder )
thanks'
May 27, 2024 at 10:24 AM #45545pixluser
ParticipantHello Peter, is it possible in views, to use thoses functions ?
- get the current post ID: get_queried_object_id()
- get terms by post ID: get_the_terms()If yes, how please.
thanks!May 27, 2024 at 10:47 PM #45554Peter
ModeratorHello,
It is possible to use those functions in the View editor. You can see in your code, you are using a WordPress function as well
get_terms()
{% set portfolios = mb.get_terms( args ) %}
View editor supports Twig, which is a PHP template engine. It doesn't mean "I bought meta box for not doing php, as I'm not a PHP coder". You should understand how the PHP function works to combine it with Twig code to use the view editor.
Following the documentation https://docs.metabox.io/extensions/mb-views/#twig
And last thing, if you are not familiar with PHP, you can contact us and request a customization code with an extra fee.
-
AuthorPosts
- You must be logged in to reply to this topic.