{"id":1914783,"date":"2021-01-25T16:30:47","date_gmt":"2021-01-25T16:30:47","guid":{"rendered":"https:\/\/toolset.com\/?post_type=course-lesson&#038;p=1914783"},"modified":"2021-03-25T09:28:13","modified_gmt":"2021-03-25T09:28:13","slug":"searching-texts-in-custom-fields-with-toolset-and-relevanssi","status":"publish","type":"course-lesson","link":"https:\/\/toolset.com\/de\/course-lesson\/searching-texts-in-custom-fields-with-toolset-and-relevanssi\/","title":{"rendered":"Searching Texts in Custom Fields with Toolset and Relevanssi"},"content":{"rendered":"\n<p>Relevanssi is a popular plugin that extends the WordPress native search capabilities as well the free text search used in Toolset custom search. It allows you to search beyond just the post title and content and find texts in custom fields.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What to install<\/h2>\n\n\n\n<p>To use Relevanssi integration in Toolset custom searches, you need the following plugins on your site:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Relevanssi, Free or Premium, 3.5 or later<\/li><li>Toolset Blocks<\/li><li>Toolset Types<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Adding Your Content Types to Relevanssi\u2019s Search Index<\/h2>\n\n\n\n<p>By default, Relevanssi includes only regular WordPress posts and pages in its search results. To make your custom post types and custom fields searchable, you need to add them to Relevanssi\u2019s index.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Including custom posts in the search<\/h3>\n\n\n\n<p>Go to the <strong>Indexing options <\/strong>on the Relevanssi <strong>Settings <\/strong>page. You will see a table that lists all post types on your site. Use checkboxes to mark all custom post types you want Relevanssi to index.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\" tb-image tb-image-media aligncenter\" data-toolset-blocks-image=\"9e2426fac08497b26bc64f9bc3c8ee59\"><a href=\"https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-marking-your-custom-post-types-as-indexable.png\"><img decoding=\"async\" width=\"1534\" height=\"830\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-marking-your-custom-post-types-as-indexable.png\" alt=\"\" class=\"wp-image-1914803\" srcset=\"https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-marking-your-custom-post-types-as-indexable.png 1534w, https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-marking-your-custom-post-types-as-indexable-300x162.png 300w, https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-marking-your-custom-post-types-as-indexable-1024x554.png 1024w, https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-marking-your-custom-post-types-as-indexable-150x81.png 150w, https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-marking-your-custom-post-types-as-indexable-768x416.png 768w, https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-marking-your-custom-post-types-as-indexable-805x436.png 805w\" sizes=\"auto, (max-width: 1534px) 100vw, 1534px\" \/><\/a><div class=\"tb-image-caption\"><figcaption>Marking your custom post types as \u201cindexable\u201d in Relevanssi\u2019s settings<\/figcaption><\/div><\/figure>\n<\/div>\n\n\n<p>Click the <strong>Save the options <\/strong>and then <strong>Build the index <\/strong>button.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\" tb-image tb-image-media aligncenter\" data-toolset-blocks-image=\"0d2c9296677ef69191f68dcb5e960397\"><a href=\"https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-relevanssi-search-options.png\"><img decoding=\"async\" width=\"1216\" height=\"371\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-relevanssi-search-options.png\" alt=\"\" class=\"wp-image-1914829\" srcset=\"https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-relevanssi-search-options.png 1216w, https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-relevanssi-search-options-300x92.png 300w, https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-relevanssi-search-options-1024x312.png 1024w, https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-relevanssi-search-options-150x46.png 150w, https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-relevanssi-search-options-768x234.png 768w, https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-relevanssi-search-options-805x246.png 805w\" sizes=\"auto, (max-width: 1216px) 100vw, 1216px\" \/><\/a><div class=\"tb-image-caption\"><figcaption>Building the search index <\/figcaption><\/div><\/figure>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\">Including custom fields in the search<\/h3>\n\n\n\n<p>You need the following two steps to include custom fields in the search:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Set up the custom fields using Types plugin.<\/li><li>Add the fields to Relevanssi settings and rebuild its search index.<\/li><\/ol>\n\n\n\n<h4 class=\"wp-block-heading\">Which custom fields can I add to Relevanssi\u2019s index with Toolset?<\/h4>\n\n\n\n<p>Views offers integration with Relevanssi for <strong>post fields<\/strong>, but not for user fields or taxonomies.<\/p>\n\n\n\n<p>You can add the following kinds of fields to Relevanssi\u2019s index:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Single line<\/strong><\/li><li><strong>Multiple line<\/strong><\/li><li><strong>WYSIWYG<\/strong><\/li><\/ul>\n\n\n\n<p>This is because these types of fields normally include text. Other fields, like checkboxes and radios don&#8217;t contain texts.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Registering Custom Fields<\/h4>\n\n\n\n<p>When creating or editing a supported custom field with the Types plugin, you will see the <strong>Include in search<\/strong> option. Select it and then save the custom field group. Finally, expand the field options again and follow the <strong>Text Search settings <\/strong>link beneath it.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\" tb-image tb-image-media aligncenter\" data-toolset-blocks-image=\"2c7d3d92a93b85963c79ec92cffcc992\"><a href=\"https:\/\/toolset.com\/wp-content\/uploads\/2021\/03\/toolset-relevanssi-including-fields-in-search.png\"><img decoding=\"async\" width=\"758\" height=\"831\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2021\/03\/toolset-relevanssi-including-fields-in-search.png\" alt=\"\" class=\"wp-image-2000363\" srcset=\"https:\/\/toolset.com\/wp-content\/uploads\/2021\/03\/toolset-relevanssi-including-fields-in-search.png 758w, https:\/\/toolset.com\/wp-content\/uploads\/2021\/03\/toolset-relevanssi-including-fields-in-search-274x300.png 274w, https:\/\/toolset.com\/wp-content\/uploads\/2021\/03\/toolset-relevanssi-including-fields-in-search-137x150.png 137w, https:\/\/toolset.com\/wp-content\/uploads\/2021\/03\/toolset-relevanssi-including-fields-in-search-474x520.png 474w, https:\/\/toolset.com\/wp-content\/uploads\/2021\/03\/toolset-relevanssi-including-fields-in-search-300x329.png 300w\" sizes=\"auto, (max-width: 758px) 100vw, 758px\" \/><\/a><div class=\"tb-image-caption\"><figcaption>Option for including the custom field in the search<\/figcaption><\/div><\/figure>\n<\/div>\n\n\n<p>You are taken to the <strong>Text Search <\/strong>tab on the <strong>Toolset \u2192 Settings <\/strong>page. Your custom field now appears in the list of all \u201cindexable\u201d fields.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\" tb-image tb-image-media aligncenter\" data-toolset-blocks-image=\"ef467322b61e7f807c931f667463b778\"><a href=\"https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-custom-fields-that-are-indexable.png\"><img decoding=\"async\" width=\"1179\" height=\"533\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-custom-fields-that-are-indexable.png\" alt=\"\" class=\"wp-image-1914883\" srcset=\"https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-custom-fields-that-are-indexable.png 1179w, https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-custom-fields-that-are-indexable-300x136.png 300w, https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-custom-fields-that-are-indexable-1024x463.png 1024w, https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-custom-fields-that-are-indexable-150x68.png 150w, https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-custom-fields-that-are-indexable-768x347.png 768w, https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-custom-fields-that-are-indexable-805x364.png 805w\" sizes=\"auto, (max-width: 1179px) 100vw, 1179px\" \/><\/a><div class=\"tb-image-caption\"><figcaption>List of your custom fields that are \u201cindexable\u201d<\/figcaption><\/div><\/figure>\n<\/div>\n\n\n<p>Check the boxes for all the fields you want added to Relevanssi. Copy the list of custom field slugs that appears underneath it, and go to the <strong>Settings <\/strong>\u2192 <strong>Relevanssi<\/strong> page.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Adding the Fields and Rebuilding the Index<\/h4>\n\n\n\n<p>Go to the <strong>Indexing options <\/strong>section of the Relevanssi Settings page, and paste the list of custom fields into the <strong>Custom fields <\/strong>field.<\/p>\n\n\n\n<p>Finally, you can click the button that saves the indexing options and rebuilds the index.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\" tb-image tb-image-media aligncenter\" data-toolset-blocks-image=\"84e575e63f2826c7887510d68952418c\"><a href=\"https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-adding-the-fields-and-rebuilding-the-index.png\"><img decoding=\"async\" width=\"1012\" height=\"759\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-adding-the-fields-and-rebuilding-the-index.png\" alt=\"\" class=\"wp-image-1914897\" srcset=\"https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-adding-the-fields-and-rebuilding-the-index.png 1012w, https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-adding-the-fields-and-rebuilding-the-index-300x225.png 300w, https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-adding-the-fields-and-rebuilding-the-index-150x113.png 150w, https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-adding-the-fields-and-rebuilding-the-index-768x576.png 768w, https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-adding-the-fields-and-rebuilding-the-index-693x520.png 693w\" sizes=\"auto, (max-width: 1012px) 100vw, 1012px\" \/><\/a><div class=\"tb-image-caption\"><figcaption>Adding the fields and rebuilding the Index<\/figcaption><\/div><\/figure>\n<\/div>\n\n\n<p>Your post types and custom fields are now part of the Relevanssi index and are searchable.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Relevanssi Search Index Works Globally<\/h2>\n\n\n\n<p>Relevanssi index and the fields that get registered work <strong>sitewide,<\/strong>&nbsp; which means that you cannot register some fields for some searches and other fields for other searches.<\/p>\n\n\n\n<p>Of course, Views allows you to control other elements in the search, like the post types to include, or whether you want to filter by a taxonomy, date, or author.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Integration with custom searches<\/h2>\n\n\n\n<p>Use the following steps to add a free text search to your custom search:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Edit the View where you want to have the text search.<\/li><li>In the <strong>Custom Search<\/strong> section of the editor click the <strong>Add Search Field<\/strong> button.<\/li><li>In the dropdown that appears, select <strong>Text search (title and content)<\/strong> option and click <strong>Next<\/strong>.<\/li><\/ol>\n\n\n<div class=\"wp-block-image\">\n<figure class=\" tb-image tb-image-media aligncenter\" data-toolset-blocks-image=\"7aa7835686bdc952eef0740c34ce5ca9\"><a href=\"https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-add-search-field-button.png\"><img decoding=\"async\" width=\"1904\" height=\"960\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-add-search-field-button.png\" alt=\"\" class=\"wp-image-1914919\" srcset=\"https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-add-search-field-button.png 1904w, https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-add-search-field-button-300x151.png 300w, https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-add-search-field-button-1024x516.png 1024w, https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-add-search-field-button-150x76.png 150w, https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-add-search-field-button-768x387.png 768w, https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-add-search-field-button-1536x774.png 1536w, https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/toolset-add-search-field-button-805x406.png 805w\" sizes=\"auto, (max-width: 1904px) 100vw, 1904px\" \/><\/a><div class=\"tb-image-caption\"><figcaption>Add Search Field button<\/figcaption><\/div><\/figure>\n<\/div>\n\n\n<p>In the block inspector expand Filed settings. It allows you to select the contents to be searched through. In our case we want the third option called <strong>Title, body and custom fields<\/strong>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\" tb-image tb-image-media aligncenter\" data-toolset-blocks-image=\"4d14f0d361e6b6b78d4e233457e536b1\"><a href=\"https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/selecting-contents-to-search-through-2.png\"><img decoding=\"async\" width=\"1904\" height=\"960\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/selecting-contents-to-search-through-2.png\" alt=\"\" class=\"wp-image-1914953\" srcset=\"https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/selecting-contents-to-search-through-2.png 1904w, https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/selecting-contents-to-search-through-2-300x151.png 300w, https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/selecting-contents-to-search-through-2-1024x516.png 1024w, https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/selecting-contents-to-search-through-2-150x76.png 150w, https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/selecting-contents-to-search-through-2-768x387.png 768w, https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/selecting-contents-to-search-through-2-1536x774.png 1536w, https:\/\/toolset.com\/wp-content\/uploads\/2021\/01\/selecting-contents-to-search-through-2-805x406.png 805w\" sizes=\"auto, (max-width: 1904px) 100vw, 1904px\" \/><\/a><div class=\"tb-image-caption\"><figcaption>Selecting contents to search through<\/figcaption><\/div><\/figure>\n<\/div>\n\n\n<p>Once you add a search filter that includes custom fields, the entire search operation is performed by the Relevanssi plugin, which means that Relevanssi is also responsible for providing the results order. This is why the Views sorting order options are not used. This includes ordering results by distance in a search for posts that include a Toolset Maps address field, where Relevanssi determines the ordering.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Known issues<\/h2>\n\n\n\n<p>On the <strong>Text Search<\/strong> tab of the <strong>Toolset<\/strong> \u2192 <strong>Settings<\/strong> page you might see a spinning wheel after changing options in the <strong>Select which custom fields to include in text searches<\/strong> section.<\/p>\n\n\n\n<p>If you take a look at your WordPress Debug Log you might find an error similar to the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PHP Fatal error: Maximum execution time of N seconds exceeded in (path to toolset)<\/code><\/pre>\n\n\n\n<p>In this case, you should increase the value of your server\u2019s PHP <strong>max_execution_time<\/strong> variable. Using the value of 90 seconds solves the issue in most cases.<\/p>\n","protected":false},"author":56710,"featured_media":1978235,"template":"","related-lesson":[8421],"class_list":["post-1914783","course-lesson","type-course-lesson","status-publish","has-post-thumbnail","hentry","related-lesson-custom-search"],"_links":{"self":[{"href":"https:\/\/toolset.com\/de\/wp-json\/wp\/v2\/course-lesson\/1914783","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/toolset.com\/de\/wp-json\/wp\/v2\/course-lesson"}],"about":[{"href":"https:\/\/toolset.com\/de\/wp-json\/wp\/v2\/types\/course-lesson"}],"author":[{"embeddable":true,"href":"https:\/\/toolset.com\/de\/wp-json\/wp\/v2\/users\/56710"}],"version-history":[{"count":7,"href":"https:\/\/toolset.com\/de\/wp-json\/wp\/v2\/course-lesson\/1914783\/revisions"}],"predecessor-version":[{"id":2000369,"href":"https:\/\/toolset.com\/de\/wp-json\/wp\/v2\/course-lesson\/1914783\/revisions\/2000369"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/toolset.com\/de\/wp-json\/wp\/v2\/media\/1978235"}],"wp:attachment":[{"href":"https:\/\/toolset.com\/de\/wp-json\/wp\/v2\/media?parent=1914783"}],"wp:term":[{"taxonomy":"related-lesson","embeddable":true,"href":"https:\/\/toolset.com\/de\/wp-json\/wp\/v2\/related-lesson?post=1914783"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}