Skip to content

Instantly share code, notes, and snippets.

@mauryaratan
Created April 2, 2014 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mauryaratan/9933024 to your computer and use it in GitHub Desktop.
Save mauryaratan/9933024 to your computer and use it in GitHub Desktop.
Make your WordPress site use WooCommerce product archives search pages by default.
<?php
function crux_search_filter( $query ) {
if ( $query->is_search ) {
$query->set( 'post_type', 'product' );
$query->is_archive = true;
$query->is_post_type_archive = true;
}
return $query;
}
add_filter( 'pre_get_posts', 'crux_search_filter' );
@daviddunnington
Copy link

@mauryaratan Hi I'm looking for this exact functionality however when I add this it does return the WooComerce archive but no products. Can you help me get this working?

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment