Reputation: 21
I have a list of products in woocommerce
when I search for a product (in admin), it always says "No Products found":
This is the URL /wp-admin/edit.php?s=Deluxe&post_status=all&post_type=product&action=-1&m=0&product_cat&product_type&paged=1&action2=-1
and when I remove product_cat
from the URL the product comes up
Upvotes: 0
Views: 2642
Reputation: 3331
The Answer from Chandrakant Devani helped, but broke other searches in the admin. Adding an if seems to avoid breakages
if ( is_admin() && $query->is_main_query() && $query->query_vars['post_type'] == 'product')
full code:
add_action( 'pre_get_posts', 'products_pre_get_posts' );
function products_pre_get_posts( WP_Query $query ) {
if ( is_admin() && $query->is_main_query() && $query->query_vars['post_type'] == 'product' ) {
$query->set( 'tax_query', array(
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => get_terms( array( 'taxonomy' => 'product_cat', 'fields' => 'ids' ) )
)
) );
}
}
Upvotes: 0
Reputation: 336
Add in the following snippet to function.php
:
add_action( 'pre_get_posts', 'products_pre_get_posts' );
function products_pre_get_posts( $query ) {
if(is_admin()){
$query->set( 'tax_query', array(
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => get_terms( array( 'taxonomy' => 'product_cat', 'fields' => 'ids' ) )
)
));
}
}
Upvotes: 2
Reputation: 762
I had the same problem. After disable the YoastSeo plugin, the search works properly again.
Upvotes: 0