Created
April 21, 2020 17:55
-
-
Save AndrewSepic/234d155a9b37d3ae0f196ac03cfb8b80 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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