Create filter by category

Support MB Views Create filter by category

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #32517
    JamesJames
    Participant

    Hi, Metabox. I would like to ask how can I filter posts based on a category? Right now it's not rendered from the archive "work" page. It's a normal page and it's showing the post but the problem is there's is no plugin that can filter for non-archive pages. Do you have any snippets of code where I can filter the post type "work" by category? Thanks.

    {% set args = { post_type: "work", posts_per_page: 6 } %}
    {% set posts = mb.get_posts( args ) %}
    
    <div class="work-grid">
        {% for post in posts %}
            <div class="grid__item">
                {{ mb.get_the_post_thumbnail( post.ID, 'large') }}
            </div>
        {% endfor %}
    </div>
    #32525
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Here is an example to query post by taxonomy

    {% set args = { post_type: "work", posts_per_page: 6, tax_query: [ { taxonomy: 'category', field: 'slug', terms: 'your-term-slug' } ] } %}

    Refer to this topic https://support.metabox.io/topic/displaying-two-cpts-in-custom-taxonomy-term/

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