Skip to content

Instantly share code, notes, and snippets.

@mauryaratan
Created April 2, 2014 12:21
Show Gist options
  • Select an option

  • Save mauryaratan/9933024 to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown

@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