Get the extra custom fields from WordPress post field

Support MB Views Get the extra custom fields from WordPress post fieldResolved

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #29385
    JamesJames
    Participant

    Hi, Is possible to display the MB custom post fields from the WordPress post field select without an MB relationship connected?

    {% for clone in post.menu_type %}
    {% for clone in clone.add_dishes %}
    {{ clone.title }}

        <!--extra fields goes here BUT doenst show without MB relation -->
        {{ post.dish_name }}
        {{ post.dish_price }}
    
    {% endfor %}
    

    {% endfor %}

    #29390
    Long NguyenLong Nguyen
    Moderator

    Hi Kirb,

    Can you please share some screenshots of the View and clarify the questions? I understand that the field dish_name and dish_price belong to the post type Dish, and you want to show it on another post type page?

    #29401
    JamesJames
    Participant

    Yes. You are right. It is added in the single store post type. So basically I want to get the custom post fields from the dish post type by adding them in the single store post type.

    Please see this screenshot of the single store page
    https://markuphero.com/share/aicr2tfAqwmQLrF5VOg2

    I want to get the custom fields from the dish and show them on the front-end. How can I do that? Because right now I'm only limited to these:

    https://markuphero.com/share/7kk9LeMW1C7PIOcmtQ0W

    #29412
    Long NguyenLong Nguyen
    Moderator

    Hi,

    So you need to create a relationship between CPT store and dish, then show the related post meta in View, please follow this documentation https://docs.metabox.io/extensions/mb-views/#relationship-fields

    and refer to these topics
    https://support.metabox.io/topic/relationship-cpt-title-not-displaying-using-mb-view-shortcode/
    https://support.metabox.io/topic/query-in-relationship-post-per-page/

    #29419
    JamesJames
    Participant

    Hi I tried this but all the dishes are all added. I just want the dishes that are only added from store page using the custom fields post.

    {% set args = { post_type: 'dish', nopaging: true} %}
    {% set dishes = mb.get_posts( args ) %}
    {% for dish in dishes %}
    
        <a href="{{ mb.get_the_permalink( dish.ID ) }}">{{ dish.post_title }}</a>
        {{ mb.rwmb_meta( 'dish_price', '', dish.ID ) }}
    
    {% endfor %}

    Please see this screenshot of the single store page
    https://markuphero.com/share/aicr2tfAqwmQLrF5VOg2

    #29421
    JamesJames
    Participant

    i tried this as well

    {% set args = { post_type: 'dish', nopaging: true} %}
    {% set dishes = mb.get_posts( args ) %}
    {% for dish in dishes %}
    
        {% for clone in post.add_menu %}
        {% for clone in clone.add_dishes %}
            {{ clone.title }}
        {% endfor %}
        {% endfor %}
    
    {% endfor %}
    #29427
    Long NguyenLong Nguyen
    Moderator

    Hi Kirb,

    You need to add the argument relationship to the variable args

    {% set args = { post_type: 'dish', nopaging: true, relationship: {id: 'store_to_dish', from: post.ID}} %}

    Please read more on this article https://metabox.io/mb-views-how-to-display-relationships/

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