Custom Fields
Re-Envisioned
Support MB Views How to show all posts for specific taxonomy?

  • Creator
    Topic
  • #21511
    Resolved EddyPiV
    Participant

    Hi,

    I am trying to show all posts for a specific taxonomy, but I am getting only the current page.
    This is what I did:
    My template settings: https://share.getcloudapp.com/bLuR5K6X
    My settings: https://share.getcloudapp.com/RBuOZn7L

    Because I want similar archive views for each value of the taxonomy, I have created a page per taxonomy, with the shortcode of the view in it.

    But the result is that I only see that page containing the shortcode with the view, actually: my current page.

    What is it that I am doing wrong?

Viewing 10 replies - 1 through 10 (of 26 total)
  • Author
    Replies
  • #21517
    Long Nguyen
    Moderator

    Hi Eddy,

    If you want to apply a view for all term archives of a taxonomy, please set the location Taxonomy Archive – All. See my screenshot https://share.getcloudapp.com/Kour1pv8.

    Then you can edit the term to get the link of the archive page https://share.getcloudapp.com/qGuNxQAP.

    #21524
    EddyPiV
    Participant

    I understand what you are saying on selecting the taxonomy archive, makes sense to me.
    So I changed it accordingly. https://share.getcloudapp.com/geuzOjGL

    But the result is the same: I only see 1 item listed: my current page, not any posts!

    Because I will have a seperate archive view for each value of the taxonomy, I think I need for each value a separate page with the shortcode of the view.
    Is that correct?

    So that’s what I did, but it’s not working.

    #21538
    Long Nguyen
    Moderator

    Hi Eddy,

    If you select the location Taxonomy Archive, just go to CPT > Taxonomy > Edit a term > View taxonomy, to get the link of the archive page. For example, the WooCommerce Product category https://share.getcloudapp.com/jkuZOJdY.

    #21541
    EddyPiV
    Participant

    Hi Long,

    The point is that the taxonomy is assigned to various posttypes: posts, media, pages, cpt’s.
    With your approach, I get them all, but I only want the posts.

    How to do that?

    #21544
    Long Nguyen
    Moderator

    Hi,

    Each post type has its own taxonomy and it is separated in the Location. See my screen record for more information https://www.loom.com/share/6368ef09af6d4072a9ba2251637ba181.

    #21583
    EddyPiV
    Participant

    Hi Long,

    I understand that the different values of the taxonomy each have their own slug.

    But what – in your example – if the block category is assigned to post, pages and cpt x, and I only want to see the items with category block for the cpt x?

    #21588
    Long Nguyen
    Moderator

    Hi,

    You can check the post type by the post ID. Here is the sample code in View.

    {% for post in query.posts %}
        {% if(mb.get_post_type(post.ID) == 'post_type_slug') %}
            {{ post.title }} - {{ post.url }}
        {% endif %}
        <br>
    {% endfor %}
    

    For more information, please follow this documentation https://developer.wordpress.org/reference/functions/get_post_type/.

    #21595
    EddyPiV
    Participant

    I just get an empty screen.

    This is the view: https://share.getcloudapp.com/Apukg9Y9
    This is the location: https://share.getcloudapp.com/DOuxKBqA
    This is the page: https://share.getcloudapp.com/z8uZbrr5
    These are the posts: https://share.getcloudapp.com/z8uZbrZQ
    This is the result: https://share.getcloudapp.com/nOukLv58

    Why am I not seeing the 2 posts that are there that meet the criteria in the location?

    #21609
    Long Nguyen
    Moderator

    Hi,

    Understand the problem, you are using the shortcode to display the view on a page but the view has set to the location archive. Use the location archive that means it only shows on the archive page as I mentioned above.

    go to CPT > Taxonomy > Edit a term > View taxonomy, to get the link of the archive page. For example, the WooCommerce Product category https://share.getcloudapp.com/jkuZOJdY

    You can also follow this documentation to know about the archive page https://developer.wordpress.org/themes/basics/template-hierarchy/.

    If you want to create a page that shows the post with specific taxonomy, please choose the location custom, then use the custom query with the function get_posts() to show posts. Here is the sample code:

    {% set args = {  post_type: 'post', posts_per_page: 5, tax_query: [ { taxonomy: 'category', field: 'slug', terms: 'block' } ] } %}
    {% set posts = mb.get_posts( args ) %}     
    {% for post in posts %}          
        {{ post.post_title }}
    {% endfor %}
    

    See my screenshot https://share.getcloudapp.com/rRu7m0p5.

    #21625
    EddyPiV
    Participant

    Okay, that clarifies that part.

    Then I proceed with the Custom view, and I will include the shortcode.

    I have adapted the view according to your advise, but it seems it finds no records: I get 5 items, each without title, excerpt etc, but all with the current date & time.
    https://share.getcloudapp.com/YEuozDmv

    https://share.getcloudapp.com/lluY8gzj

Viewing 10 replies - 1 through 10 (of 26 total)
  • You must be logged in to reply to this topic.