{"id":1621213,"date":"2020-05-13T14:19:26","date_gmt":"2020-05-13T14:19:26","guid":{"rendered":"https:\/\/toolset.com\/?post_type=course-lesson&#038;p=1621213"},"modified":"2021-05-18T16:36:02","modified_gmt":"2021-05-18T16:36:02","slug":"creating-a-custom-search","status":"publish","type":"course-lesson","link":"https:\/\/toolset.com\/es\/course-lesson\/creating-a-custom-search\/","title":{"rendered":"Creating a Custom Search"},"content":{"rendered":"\n<p>With Toolset, you choose what to search by, how to style the search box, and how to display the results.<\/p>\n\n\n\n<p>You can also enable pagination, AJAX updates, and sorting to enhance the custom search and make it more usable for sites that have a lot of content.<\/p>\n\n\n\n<p>Besides this you can display custom search results on a map, or set up the search box and results results side-by-side.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"tb-heading aligncenter\" data-toolset-blocks-heading=\"87c4bdccfa399f1ee4ff708833638ada\" data-last-update=\"1.4\">Custom searches built using Toolset<\/h4>\n\n\n\n<div class=\"wp-block-toolset-blocks-grid tb-grid\" data-toolset-blocks-grid=\"3d9c399fe625e1b972f817a0680229f6\">\n<div class=\"wp-block-toolset-blocks-grid-column tb-grid-column tb-grid-align-top\" data-toolset-blocks-grid-column=\"3034fbe886c11054e95b46b09d3e4112\">\n<figure class=\"wp-block-image tb-image tb-image-media\" data-toolset-blocks-image=\"15b84a70216289f534cdadbcc8191dea\"><a href=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/05\/toolset-search-features-realestate.png\"><img decoding=\"async\" width=\"955\" height=\"580\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/05\/toolset-search-features-realestate.png\" alt=\"\" class=\"wp-image-1635957\" srcset=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/05\/toolset-search-features-realestate.png 955w, https:\/\/toolset.com\/wp-content\/uploads\/2020\/05\/toolset-search-features-realestate-300x182.png 300w, https:\/\/toolset.com\/wp-content\/uploads\/2020\/05\/toolset-search-features-realestate-150x91.png 150w, https:\/\/toolset.com\/wp-content\/uploads\/2020\/05\/toolset-search-features-realestate-768x466.png 768w, https:\/\/toolset.com\/wp-content\/uploads\/2020\/05\/toolset-search-features-realestate-805x489.png 805w\" sizes=\"auto, (max-width: 955px) 100vw, 955px\" \/><\/a><div class=\"tb-image-caption\"><figcaption>Custom search for properties<\/figcaption><\/div><\/figure>\n\n\n\n<p><\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-toolset-blocks-grid-column tb-grid-column tb-grid-align-top\" data-toolset-blocks-grid-column=\"3034fbe886c11054e95b46b09d3e4112\">\n<figure class=\"wp-block-image tb-image tb-image-media\" data-toolset-blocks-image=\"daca436faf06cbacb2bda07bcb46cc7b\"><a href=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/05\/toolset-search-features-travel-destination.png\"><img decoding=\"async\" width=\"955\" height=\"580\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/05\/toolset-search-features-travel-destination.png\" alt=\"\" class=\"wp-image-1635965\" srcset=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/05\/toolset-search-features-travel-destination.png 955w, https:\/\/toolset.com\/wp-content\/uploads\/2020\/05\/toolset-search-features-travel-destination-300x182.png 300w, https:\/\/toolset.com\/wp-content\/uploads\/2020\/05\/toolset-search-features-travel-destination-150x91.png 150w, https:\/\/toolset.com\/wp-content\/uploads\/2020\/05\/toolset-search-features-travel-destination-768x466.png 768w, https:\/\/toolset.com\/wp-content\/uploads\/2020\/05\/toolset-search-features-travel-destination-805x489.png 805w\" sizes=\"auto, (max-width: 955px) 100vw, 955px\" \/><\/a><div class=\"tb-image-caption\"><figcaption>Custom search for travel destinations<\/figcaption><\/div><\/figure>\n<\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">On this page<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"#steps-for-creating-custom-searches\">Steps for creating custom searches<\/a><\/li><li><a href=\"#make-the-search-results-update-when-search-inputs-change\">Make the search results update when search inputs change<\/a><\/li><li><a href=\"#add-front-end-sorting-to-search-results\">Add front-end sorting to search results<\/a><\/li><li><a href=\"#add-pagination-to-search-results\">Add pagination to search results<\/a><\/li><li><a href=\"#style-the-search-box-and-results\">Style the search box and results<\/a><\/li><li><a href=\"#display-the-search-box-and-search-results-on-different-pages\">Display the search box and search results on different pages<\/a><\/li><li><a href=\"#display-the-search-box-and-search-results-side-by-side\">Display the search box and search results side-by-side<\/a><\/li><li><a href=\"#hide-the-search-results-until-the-first-search\">Hide the search results until the first search<\/a><\/li><li><a href=\"#display-the-search-results-on-a-map\">Display the search results on a map<\/a><\/li><li><a href=\"#how-to-search-by-post-relationships\">How to search by post relationships<\/a><\/li><li><a href=\"#enable-custom-search-for-existing-views\">Enable custom search for existing Views<\/a><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Steps for creating custom searches<\/h2>\n\n\n\n<p>There are two main steps for creating a custom search:<\/p>\n\n\n\n<div class=\"wp-block-toolset-blocks-grid tb-grid\" data-toolset-blocks-grid=\"c6b972590259fc930bc051af7a3729c8\">\n<div class=\"wp-block-toolset-blocks-grid-column tb-grid-column tb-grid-align-top\" data-toolset-blocks-grid-column=\"207161a1d7b19d67f566c5a1190160c7\">\n<p>1. <strong>Create the custom search box<\/strong><\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-toolset-blocks-grid-column tb-grid-column tb-grid-align-top\" data-toolset-blocks-grid-column=\"207161a1d7b19d67f566c5a1190160c7\">\n<p><strong>2. Design the custom search results<\/strong><\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-toolset-blocks-grid-column tb-grid-column tb-grid-align-top\" data-toolset-blocks-grid-column=\"3034fbe886c11054e95b46b09d3e4112\"><div class=\"wp-block-image\">\n<figure class=\" tb-image tb-image-media aligncenter\" data-toolset-blocks-image=\"ae170d17b07ace32acfe035ede4b4133\"><a href=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/05\/toolset-custom-search-form.png\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/05\/toolset-custom-search-form-400x255.png\" alt=\"\" class=\"wp-image-1636583\"\/><\/a><\/figure>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-toolset-blocks-grid-column tb-grid-column tb-grid-align-top\" data-toolset-blocks-grid-column=\"3034fbe886c11054e95b46b09d3e4112\"><div class=\"wp-block-image\">\n<figure class=\" tb-image tb-image-media aligncenter\" data-toolset-blocks-image=\"4817be3045dd5682d1d4719a42f5a2be\"><a href=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/05\/toolset-custom-search-results.png\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/05\/toolset-custom-search-results-500x319.png\" alt=\"\" class=\"wp-image-1636593\"\/><\/a><\/figure>\n<\/div><\/div>\n<\/div>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>It doesn&#8217;t matter which of these steps you do first. However, having at least simple search results makes it easier to test the search form.<\/p>\n\n\n\n<p>Here is an example of a complete custom search, with both the box and the results.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\" tb-image tb-image-media aligncenter\" data-toolset-blocks-image=\"f2db9ebb7bd06539b3a8efffd3c15c67\"><a href=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/05\/toolset-custom-search-complete.png\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/05\/toolset-custom-search-complete-500x381.png\" alt=\"\" class=\"wp-image-1636603\"\/><\/a><div class=\"tb-image-caption\"><figcaption>Custom search with the search form and search results<\/figcaption><\/div><\/figure>\n<\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">1. Creating the custom search form<\/h3>\n\n\n\n<p>You start by inserting a&nbsp;<a href=\"https:\/\/toolset.com\/es\/glossary\/view\/\">View<\/a> block into your page.<\/p>\n\n\n\n<p>In the View creation wizard, enable the&nbsp;<strong>Search&nbsp;<\/strong>option.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\" tb-image tb-image-media aligncenter\" data-toolset-blocks-image=\"443f6c7f8063c6f6143079a01e07a4c9\"><a href=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/05\/toolset-views-custom-search-1.png\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/05\/toolset-views-custom-search-1-500x335.png\" alt=\"\" class=\"wp-image-1635975\"\/><\/a><div class=\"tb-image-caption\"><figcaption>Enabling the custom search when creating a new View<\/figcaption><\/div><\/figure>\n<\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>After finishing the View creation wizard there is a&nbsp;<strong>View Search&nbsp;<\/strong>section in the View\u2019s editing area. Use the available buttons to add a custom search field, insert submit and reset buttons, or add other blocks.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\" tb-image tb-image-media aligncenter\" data-toolset-blocks-image=\"9281343146de78fbd5613b4a7ac06947\"><a href=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/05\/toolset-views-custom-search-2.png\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/05\/toolset-views-custom-search-2-500x272.png\" alt=\"\" class=\"wp-image-1636007\"\/><\/a><div class=\"tb-image-caption\"><figcaption>Custom search section when editing a View block<\/figcaption><\/div><\/figure>\n<\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>For example, you can click to&nbsp;<strong>Add Search Field&nbsp;<\/strong>and use the&nbsp;<strong>Select a Field&nbsp;<\/strong>dropdown. Select by which content type you want users to be able to search by and click&nbsp;<strong>Next<\/strong>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\" tb-image tb-image-media aligncenter\" data-toolset-blocks-image=\"bd932bacbed239099b2bfe279cc17c35\"><a href=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/05\/toolset-views-custom-search-3.png\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/05\/toolset-views-custom-search-3-500x293.png\" alt=\"\" class=\"wp-image-1636015\"\/><\/a><div class=\"tb-image-caption\"><figcaption>Adding a custom search field<\/figcaption><\/div><\/figure>\n<\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>You can now use the right sidebar to tweak the options for this search field. This includes the main field settings, label and style options.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\" tb-image tb-image-media aligncenter\" data-toolset-blocks-image=\"70f570b61cd0f32226787b7a158e298d\"><a href=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/05\/toolset-views-custom-search-4.png\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/toolset.com\/wp-content\/uploads\/2020\/05\/toolset-views-custom-search-4-500x183.png\" alt=\"\" class=\"wp-image-1636041\"\/><\/a><\/figure>\n<\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">2. Creating the search results<\/h3>\n\n\n\n<p>The results of a custom search is basically a list of posts. In Toolset, we call such lists Views. Instead of <a href=\"https:\/\/toolset.com\/es\/glossary\/wp_query\/\">writing custom queries<\/a>, Toolset does everything for you. All you need to do is visually design what and how you want to display for each post.<\/p>\n\n\n\n<p>You create a View using Toolset blocks as they allow you to display <a href=\"https:\/\/toolset.com\/es\/glossary\/dynamic-fields\/\">dynamic content<\/a> coming from custom fields, taxonomies, and standard post fields. You can then use the styling options within each Toolset block to design how the list will look like.<\/p>\n\n\n\n<p>You can even <a href=\"https:\/\/toolset.com\/documentation\/dynamic-sources-in-popular-blocks\/\">display Dynamic Sources using WordPress core blocks and popular block plugins<\/a>. Insert them and in the right sidebar, expand the&nbsp;<strong>Dynamic Sources&nbsp;<\/strong>section. Toggle on the option for any of the supported fields in that block.<\/p>\n\n\n\n<p>Toolset even allows you to display&nbsp;Dynamic Sources inside any text blocks like headings, buttons, and more. For more information, check out the lesson about&nbsp;<a href=\"https:\/\/toolset.com\/es\/course-lesson\/display-dynamic-sources-inside-all-text-blocks\/\">displaying Inline Fields<\/a>.<\/p>\n\n\n\n<p>You can also enhance search results by adding pagination, front-end sorting, or making results update when search inputs change.<\/p>\n\n\n\n<div class=\"tb-fields-and-text\" data-toolset-blocks-fields-and-text=\"360284519b991feb492b582c7d84725f\"><p>For more information see below and in the lesson about <a href=\"https:\/\/toolset.com\/es\/course-lesson\/creating-a-view\/\">creating custom lists of posts<\/a>.<\/p><\/div>\n\n\n\n<p><\/p>\n","protected":false},"author":4341,"featured_media":1663117,"template":"","related-lesson":[8421],"class_list":["post-1621213","course-lesson","type-course-lesson","status-publish","has-post-thumbnail","hentry","related-lesson-custom-search"],"_links":{"self":[{"href":"https:\/\/toolset.com\/es\/wp-json\/wp\/v2\/course-lesson\/1621213","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/toolset.com\/es\/wp-json\/wp\/v2\/course-lesson"}],"about":[{"href":"https:\/\/toolset.com\/es\/wp-json\/wp\/v2\/types\/course-lesson"}],"author":[{"embeddable":true,"href":"https:\/\/toolset.com\/es\/wp-json\/wp\/v2\/users\/4341"}],"version-history":[{"count":8,"href":"https:\/\/toolset.com\/es\/wp-json\/wp\/v2\/course-lesson\/1621213\/revisions"}],"predecessor-version":[{"id":2027495,"href":"https:\/\/toolset.com\/es\/wp-json\/wp\/v2\/course-lesson\/1621213\/revisions\/2027495"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/toolset.com\/es\/wp-json\/wp\/v2\/media\/1663117"}],"wp:attachment":[{"href":"https:\/\/toolset.com\/es\/wp-json\/wp\/v2\/media?parent=1621213"}],"wp:term":[{"taxonomy":"related-lesson","embeddable":true,"href":"https:\/\/toolset.com\/es\/wp-json\/wp\/v2\/related-lesson?post=1621213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}