Home Forums General Issues WP_QUERY to multi selection taxonomy field


WP_QUERY to multi selection taxonomy field

  • Hi, I’m trying to make a WP_QUERY to a multi selection taxonomy field.

    – Testimonial Custom Post Type
    – Product Custom Post Type with product category
    – ACF multi selection taxonomy field return term ID for Testimonial CPT

    What I want to achieve:
    When I view a product, it will display testimonial based on the product category assigned to that product. Testimonial of that product is identified via ACF tax field.

    For example, if a testimonial has fish and veg selected in the ACF tax field, any products that has fish and/or veg categories assigned should display that testimonial.

    My WP_QUERY:

    $args = array(     
    	'posts_per_page' => 3,
    	'paged' => -1,
    	'post_type' => 'test_type', // testimonial CPT
    	'post_status' => 'publish',
    	'orderby' => 'date',
    	'order' => 'desc',
    	'meta_query' => array(
    		'relation' => 'OR',
    			'key' => 't_categories', // ACF tax field name
    			'value'   => $cate->term_id, // Current product category
    			'compare' => '='

    The problem:
    I’m not sure what I did incorrectly, but it only returns testimonial with one category selected. Testimonial that has more than one categories selected in ACF tax field won’t display.

    So, can anyone tell me what I have done wrong here?


Viewing 1 post (of 1 total)

The topic ‘WP_QUERY to multi selection taxonomy field’ is closed to new replies.