Support

Account

Home Forums General Issues 'Post Object' field, exclusion filter based on taxonomy?

Solved

'Post Object' field, exclusion filter based on taxonomy?

  • Hi folks …

    I have set up a custom field using the “Post Object” type. It’s only used in the back-end, on the post editor for the CPT in question.

    It is referencing the products in database (from Woocommerce). I have set up a filter to only include those items with publish post_status. For that I set up the following function:

    function cpt_review_product_filter( $args ) {
    	$args['post_status'] = array( 'publish' );
    	return $args;
    }
    add_filter( 'acf/fields/post_object/query/name=review_product', 'cpt_review_product_filter' );

    That worked fine. What I’d like to add to this filter is to exclude items that are in a specific category.

    I tried adding the following two (separately) lines, but neither worked. So I am obviously over-looking something.

    
        $args['term_id'] != '562' ;
        $args['product_cat'] != 'THE-CATEGORY-TO-EXCLUDE';
    

    My question …
    How can I filter out results that have a specific category assigned to them? (keeping in mind, these items are likely in numerous categories, but so long as one of their categories has ID 562 (in my case), I want to exclude it.

    Thanks very much …

    Jonathan

  • You need to add a tax_query as explained in the WP_Query() docs.

  • Thanks John. That helps.

    I’ve figured out how to get that work in the positive (e.g. items IS in array).

    Would you please give a tip on how to make that a negative? As in, I need to NOT include the item if it’s in the array.

    Cheers,

    Jonathan

  • Solved. Simply had to add an 'operator' ⇒ 'NOT IN', to the array look-up.
    Done.
    Thank you.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.