Skip to content

Instantly share code, notes, and snippets.

@AndrewSepic
Created April 21, 2020 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndrewSepic/234d155a9b37d3ae0f196ac03cfb8b80 to your computer and use it in GitHub Desktop.
Save AndrewSepic/234d155a9b37d3ae0f196ac03cfb8b80 to your computer and use it in GitHub Desktop.
function healthyliving_remove_product_cats( $query ) {
$hidden_shop_categories = get_field('hidden_shop_categories', 'option');
// Comment out the line below to hide products in the admin as well
if ( is_admin() ) return;
if ( $query->is_search ) {
$query->set( 'tax_query', array(
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => $hidden_shop_categories,
'operator' => 'NOT IN',
)
) );
}
}
add_action( 'pre_get_posts', 'healthyliving_remove_product_cats' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment