Skip to content

Instantly share code, notes, and snippets.

@WillBrubaker
Created April 27, 2017 17:42
Show Gist options
  • Select an option

  • Save WillBrubaker/b6971d0d77f8c5b0738d181ade7ef448 to your computer and use it in GitHub Desktop.

Select an option

Save WillBrubaker/b6971d0d77f8c5b0738d181ade7ef448 to your computer and use it in GitHub Desktop.
Display WooCommerce Photography Products in Shop
add_action( 'pre_get_posts', 'handsome_bearded_guy_show_photograhpy_products', 99 );
function handsome_bearded_guy_show_photograhpy_products( $query ) {
if ( ! $query->is_main_query() || is_admin() ) {
return;
}
if ( isset( $query->query_vars['tax_query'] ) && is_post_type_archive( 'product' ) || ( is_page() && isset( $query->query_vars['page_id'] ) && wc_get_page_id( 'shop' ) == $query->query_vars['page_id'] ) && ! is_search() ) {
foreach ( $query->query_vars['tax_query'] as $key => $arr ) {
if ( in_array( 'photography', $arr['terms'] ) ) {
unset( $query->query_vars['tax_query'][ $key ] );
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment