Support Forum
Hi,
I'm trying to build a view based on CPT that only pulls from a set category but the args ignore both the CPT and the category this is what I have so far:
{% set args = {post_type: 'project', posts_per_page: 10, cat: 16 } %}
<div class="sidebarnews">
{% set posts = mb.get_posts( args ) %}
<ul>
{% for post in posts %}
<li><img src="{{ post.thumbnail.medium.url }}" width="{{ post.thumbnail.medium.width }}" height="{{ post.thumbnail.medium.height }}" alt="{{ post.thumbnail.medium.alt }}">
{% for item in post.logo %}
<img src="{{ item.medium.url }}" width="{{ item.medium.width }}" height="{{ item.medium.height }}" alt="{{ item.medium.alt }}">
{% endfor %}</li>
{% endfor %}
</ul>
</div>
Alan
Hi Alan,
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().
Refer to this topic https://support.metabox.io/topic/mb-view-by-shortcode/
Hi,
I'm still a bit confused I'm not sure what I need to do.
Could you please show me an example.
Thanks.
Update,
I've now got the images to show using this code below. Could you tell me how I can make it only pull the information from a certain post category.
<div class="sidebarnews">
{% set args = {post_type: 'project', posts_per_page: 10} %}
{% 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>
Hi,
You need to add the argument taxonomy
to get posts from certain taxonomy.
{% set args = { post_type: 'project', posts_per_page: 10, tax_query: [ { taxonomy: 'taxonomy-slug', field: 'slug', terms: 'term-slug' } ] } %}
Refer to this topic https://support.metabox.io/topic/displaying-two-cpts-in-custom-taxonomy-term/
Hi,
Thanks for all your help that worked perfectly!