12% off of LTD using this coupon: TWELVEPERCENTOFF. Promo ends on 2 Dec midnight UTC.
Published on May 25, 2021

How to exclude product categories from Oxygen

Sridhar Katakam

This tutorial provides the steps to exclude one or more product categories when using a manual query in Oxygen‘s Easy Posts or Repeater for showing WooCommerce products.

Note: This is for secondary loops. For main queries, use pre_get_posts outside the Oxygen’s editor using a plugin like Code Snippets.

Step 1

In the Oxygen editor, add a Code Block having:

<?php
	$args = array(
		'post_type' => 'product',
		'posts_per_page' => 10,
		'no_found_rows' => true,
		'tax_query' => array(
			array(
				'taxonomy' => 'product_cat',
				'field'    => 'slug',
				'terms'    => array( 'decor' ),
				'operator' => 'NOT IN'
			),
		),
	);

	echo build_query( $args );
?>

Enter the slugs of product categories that you wish to exclude in the

'terms'    => array( 'decor' ),

line. decor is the slug in this example. To exclude multiple product categories, enter them comma-separated like this:

'terms'    => array( 'decor', 'music' ),

Visit the page on the frontend and copy the generated query string.

Ex.:

post_type=product&posts_per_page=10&no_found_rows=1&tax_query%5B0%5D%5Btaxonomy%5D=product_cat&tax_query%5B0%5D%5Bfield%5D=slug&tax_query%5B0%5D%5Bterms%5D%5B0%5D=decor&tax_query%5B0%5D%5Boperator%5D=NOT IN

We are done with the Code Block. So it can be deleted now.

Step 2

In your Easy Posts/Repeater component, set the query type to manual and paste the above string.

References

tagschevron-leftchevron-rightchainangle-rightangle-upangle-downfolder-omagnifiercrossmenuchevron-down