Custom Fields
Support MB Views How do display CPT with selected taxonomy anywhere on the site?

  • Creator
  • #21498
    Resolved Adam

    I have created a custom post type, Testimonials.

    I have created a taxonomy called Testimonial Categories which is used by the Testimonials CPT. It includes three categories, Coaching, Growth, and Planning.

    I have a Testimonials archive page set up using MB Views and it is correctly displaying all testimonials.

    The client would also like testimonials displayed on specific pages depending on the testimonials' selected categories. So only testimonials categorized as Planning, for example, would display on the Planning page. However, I am not sure how to do this. Here is what I currently have set up:

    Any idea how I can achieve this?


Viewing 4 replies - 1 through 4 (of 4 total)
  • Author
  • #21499

    Sorry, images aren't embedding for me. Here are the links.



    Long Nguyen

    Hi Adam,

    To apply the view for a specific term archive, please use the Location > Select Taxonomy Archive > Select a term. See my screenshot


    Hrm... I figured out the sorting part via a PHP function. However, in the view I want to get it by category. I know my PHP pretty well and could see creating a template file, but I am wanting to accomplish this via the View with Twig.

    Here is a bit of code I have that pulls the testimonials, but I am wanting the testimonials that have the category of "planning"

            {% set args = {  post_type: "testimonials", posts_per_page: 20 } %}
            {% set posts = mb.get_posts( args ) %}          
            {% for key, post in posts %}          
                    <span>{{ post.post_title}}</span>               
            {% endfor %}

    This grabs just that. But arguments like cat: "planning" and such do not work. Is there an example anywhere I can see to pull in that category?


    Long Nguyen


    To get posts by custom taxonomy, please use the argument tax_query. Here is the sample code:

    {% set args = {  post_type: 'testimonials', posts_per_page: 20, tax_query: [ { taxonomy: 'testimonial_category', field: 'slug', terms: 'planning' } ] } %}

    For more information about arguments, please follow this documentation

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