Get the extra custom fields from WordPress post field
- This topic has 6 replies, 2 voices, and was last updated 3 years, 10 months ago by
Long Nguyen.
-
AuthorPosts
-
July 9, 2021 at 4:24 AM #29385
James
ParticipantHi, 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 %}
July 9, 2021 at 11:11 AM #29390Long Nguyen
ModeratorHi Kirb,
Can you please share some screenshots of the View and clarify the questions? I understand that the field
dish_name
anddish_price
belong to the post type Dish, and you want to show it on another post type page?July 9, 2021 at 10:38 PM #29401James
ParticipantYes. 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 singlestore
post type.Please see this screenshot of the single store page
https://markuphero.com/share/aicr2tfAqwmQLrF5VOg2I 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:
July 10, 2021 at 3:32 PM #29412Long Nguyen
ModeratorHi,
So you need to create a relationship between CPT
store
anddish
, then show the related post meta in View, please follow this documentation https://docs.metabox.io/extensions/mb-views/#relationship-fieldsand 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/July 11, 2021 at 2:14 AM #29419James
ParticipantHi 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 fieldspost
.{% 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/aicr2tfAqwmQLrF5VOg2July 11, 2021 at 2:41 AM #29421James
Participanti 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 %}
July 11, 2021 at 11:08 PM #29427Long Nguyen
ModeratorHi Kirb,
You need to add the argument
relationship
to the variableargs
{% 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/
-
AuthorPosts
- You must be logged in to reply to this topic.