Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

daviddunnington commented Apr 24, 2018

@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
You can’t perform that action at this time.