Answer the question
In order to leave comments, you need to log in
How to display products that contain the search word?
I received a task from an SEO specialist to make it possible to create a block with products by search query in the admin panel.
That is, he presses the create block button, enters a search query, and a block appears on the page with a set of products that match this query.
Everything is generally clear except for one thing - how to display products by search word? You need to search everywhere, starting from the title, category and tags, ending with the description and custom fields.
I studied a set of shortcodes in wookomers and did not find anything suitable.
The site currently uses the Search by Omega plugin for search. Maybe you can create blocks through it?
Answer the question
In order to leave comments, you need to log in
B wp_query()
has an argument 's'
to which you can pass a search query
$args = [
'post_type' => 'product',
's' => 'search phrase',
];
$query = new WP_Query( $args );
post_title
, post_excerpt
, post_content
. If you need to fix this behavior, look for, for example, wp_query search by post meta , there are solutions. Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question