MB view by shortcode

Support MB Views MB view by shortcodeResolved

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #28092
    Régis EvennouRégis Evennou
    Participant

    Hi,
    I am quite new in premium version, i am discovering all abilities of extensions... It is great !

    I am missing someting with view and shortcode, HTML tags display well in page but no custom fields.

    How to query my post type ?

    Answer must be easy... Thank you for your help.

    screen

    #28099
    Régis EvennouRégis Evennou
    Participant

    i tried this, it should work ?

    <div class="markets">
        {% set args = {post_type: "market", posts_per_page: 3} %}
        {% set posts = mb.get_posts( args ) %}
        {% for post in posts %}
            {{ post.title }}
        {% endfor %}
    </div>
    #28100
    Régis EvennouRégis Evennou
    Participant

    Ok, i can display the text field (text_test) 🙂
    But not the image (logo_markey) 🙁

    <div class="markets">    
        {% set args = {post_type: 'market', posts_per_page: -1} %}
        {% set posts = mb.get_posts( args ) %}
    
        {% for post in posts %} 
    
            {# Text #}
            {{ post.text_test }}
    
            {# Image #}
            <img src="{{ post.logo_markey.full.url }}">
    
        {% endfor %}    
    </div>
    #28111
    Régis EvennouRégis Evennou
    Participant

    Ok, it works for me now 🙂

    <div class="markets">    
        {% set args = {post_type: 'market', posts_per_page: -1} %}
        {% set posts = mb.get_posts( args ) %}
        {% for post in posts %} 
            {# Image #}
            {% set image = mb.rwmb_meta( 'logo_market', '', post.ID ) %}
            <img src="{{ image['full_url'] }} "> 
        {% endfor %}    
    </div>

    I do not understand why i can not use mb view UI to insert this {{ post.logo_market.thumbnail.url }}...
    Someone can explain ?
    Thank you

    #28116
    Long NguyenLong Nguyen
    Moderator

    Hi Régis,

    Thank you for reaching out.

    If you use the function get_posts(), it will return post objects, we can call it a custom query. A post object does not support to access the field ID as a property of it.

    You can get the post info via the post ID in a custom query by using the WordPress functions or our helper function rwmb_meta(). For example, featured image, use the function get_the_post_thumbnail().

    <div class="markets">    
        {% set args = {post_type: 'market', posts_per_page: -1} %}
        {% set posts = mb.get_posts( args ) %}
        {% for post in posts %} 
            {# Image #}
            {% set image = mb.rwmb_meta( 'logo_market', '', post.ID ) %}
            <img src="{{ image['full_url'] }} "> 
    
            {{ mb.get_the_post_thumbnail( post.ID, 'thumbnail' ) }}
        {% endfor %}    
    </div>
    #28130
    Régis EvennouRégis Evennou
    Participant

    I will study taht 🙂
    Thank you

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