How to create an internal search engine that looks for product ingredients?
-
I need to create an internal search engine on the web to find the products in the catalog by their ingredients, and not by categories, SKU, labels, etc…
I was looking for the option to find how to customize without using a Plugin
The handicap is that I need to search the products by ingredients that certain products do not contain. I mean, there are people who are allergic to some products and cannot eat various ingredients, and the serious need is to give them the opportunity to look for products that do not have the ingredients that they are allergic to.
For example, enter the word “sugar” in the search engine, and all products that do not have sugar among their ingredients appear
Surely someone has already had this idea.
In the case that I show, the search is filtered by categories and tags<form role="search" method="get" class="search-form" action="<?php echo home_url( '/' ); ?>"> <label> <span class="screen-reader-text"><?php echo _x( 'Search for:', 'label' ) ?></span> <input type="search" class="search-field" placeholder="<?php echo esc_attr_x( 'Search …', 'placeholder' ) ?>" value="<?php echo get_search_query() ?>" name="s" title="<?php echo esc_attr_x( 'Search for:', 'label' ) ?>" /> </label> <select id="category_name" name="category_name"> <option value="">Todas</option> <?php $categories = get_categories(); foreach ($categories as $key => $category) {?> <option value="<?php echo $category->slug;?>"><?php echo $category->name;?></option> <?php }?> </select> <select id="tag" name="tag"> <option value="">Todas</option> <?php $tags = get_tags(); foreach ($tags as $key => $tag) {?> <option value="<?php echo $tag->slug;?>"><?php echo $tag->name;?></option> <?php }?> </select> <input type="submit" class="search-submit" value="<?php echo esc_attr_x( 'Search', 'submit button' ) ?>" /> </form> <?php
I know that you can limit the search content, for example with
"post_type"
<input type="hidden" name="post_type" value="post" />
function my_custom_searchengine($query) { if ($query->is_search && !is_admin()) { $query->set('post_type', array('post')); } return $query; } add_filter( 'pre_get_posts', 'my_custom_searchengine' );
But I don’t know which are the “
posts
” that I should add, I don’t know how to perform this search for the product description field, I don’t know how to make it work, and find products that do not contain the search ingredients
Everything would be in modifying the"select"
fields, in the search engine, but I don’t understand what would be the Query that should be added in the"values"
of the"select"
, taking into account that the ingredients are only in the product description.
Since WordPress allows you to extend the search to custom fields, this could be done with “mata_query” .
How could I get this?
Should I create an “array” with the ingredients of all the products?Any ideas ?
Thank you
- The topic ‘How to create an internal search engine that looks for product ingredients?’ is closed to new replies.