MB Views doesn't show data in front

Support MB Views MB Views doesn't show data in frontResolved

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #40758
    MilosMilos
    Participant

    Hello, I have problem to show data from Field Groups in MB View.

    Field Group name is Tickets fields, it has just one field ticket ( type is group) and it's Cloneable field.
    Inside of this field group I have subfileds with id's ( team_1, team_2, prediction, betting_odd, datetime_game)

    In Views I created Ticket view and I used Insert Field button to get all data. this is the code:

    <h3>TEST</h3>
    
    {% for clone in post.ticket %}
    	{{ clone.team_1 }}
    	<br>
    	{{ clone.team_2 }}
    	<br>
    	{{ clone.prediction }}
    	<br>
    	{{ clone.betting_odd }}
    	<br>
    	{{ clone.datetime_game | date( 'F j, Y' ) }}
    {% endfor %}

    For some reason I can see anything in front, I tried with shorcode, and with single page view, but all what I can see is h3 test...

    Anybody knows what could be the problem ?
    Thanks

    #40760
    PeterPeter
    Moderator

    Hello,

    The code looks good and works correctly on my local site. Can you please share some screenshots of the View template, post editing and value output?

    #40764
    MilosMilos
    Participant

    Hi Peter thank you for your replay, yes everthing looks correct but still is not working.

    I will share with you here few screenshots, I hope it can help:

    https://postimg.cc/gallery/0sghV0B

    If I try to output anything from {% for clone in post.ticket %} I always get Null

    #40771
    PeterPeter
    Moderator

    Hello,

    Thanks, I see that issue. The custom fields are associated with the post type ticket so if you use the shortcode or assign the view template to a single page, the code post.ticket will return nothing because there is no field value ticket associated with the page.

    To display a custom field associated with a post on a page, you can use the helper function rwmb_meta() and pass the post ID to the third parameter to get the field value.

    For example:

    {% set tickets = mb.rwmb_meta( 'ticket', '', 123 ) %}
    {% for clone in tickets %}
    ...

    where 123 is the ticket post ID.

    Please read more on the documentation
    https://docs.metabox.io/functions/rwmb-meta/
    https://docs.metabox.io/extensions/mb-views/#running-php-functions

    #40782
    MilosMilos
    Participant

    Hello Peter thanks for help,
    After reading documentation that you shared I manage to get data that I wanted.
    I will share here code if somebody have similar problem.

    <h3>TEST Tiketi</h3>
    
    {% set args = { post_type: 'ticket', posts_per_page: -1 } %}
    {% set posts = mb.get_posts( args ) %}
    {% for post in posts %}
    
        {# Tickets: #}
        {% set tickets = mb.rwmb_meta( 'ticket', '', post.ID ) %}
    	
    		{% for ticket in tickets %}
    
    		 {# {{ ticket.team_1 | json_encode(constant('JSON_PRETTY_PRINT')) }}  #}
    
    		 <br>
    		 {{ ticket.team_1 }} 
    		 <br>
    		 {{ ticket.team_2 }} 
    		 <br>
    		{{ ticket.prediction }} 
    		 
    		{% endfor %}
    
    			<div><hr></div>	
    
       
    {% endfor %}
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.