I want to write the custom query to search product by its description. By default the WooCommerce search doesn’t include the searching by description. I am using the query_posts
function to get products. Here is my code:
$args = array(
's' => $search_keyword,
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'meta_query' => array(
array(
'key' => '_visibility',
'value' => array( 'search', 'visible' ),
'compare' => 'IN'
)
)
);
$products = get_posts( $args );
If you are wanting to search the product description, you are going to have to search the
post_content
. I don’t think you’ll be able to do that usingget_posts()
orWP_Query()
. The only way to do that is to write a custom SQL query.For your example, you’d need something like the following: