MB view by shortcode
- This topic has 5 replies, 2 voices, and was last updated 4 years ago by
Régis Evennou.
-
AuthorPosts
-
May 11, 2021 at 3:49 PM #28092
Régis Evennou
ParticipantHi,
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.
May 11, 2021 at 8:21 PM #28099Régis Evennou
Participanti 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>
May 11, 2021 at 9:15 PM #28100Régis Evennou
ParticipantOk, 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>
May 12, 2021 at 12:56 AM #28111Régis Evennou
ParticipantOk, 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 youMay 12, 2021 at 6:19 AM #28116Long Nguyen
ModeratorHi 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>
May 12, 2021 at 9:56 PM #28130Régis Evennou
ParticipantI will study taht 🙂
Thank you -
AuthorPosts
- You must be logged in to reply to this topic.