{"id":2524,"date":"2026-10-20T08:34:13","date_gmt":"2026-10-20T07:34:13","guid":{"rendered":"https:\/\/wpgeodirectory.com\/documentation\/article\/customise-search-on-category-pages\/"},"modified":"2026-10-20T08:41:01","modified_gmt":"2026-10-20T07:41:01","slug":"customise-search-on-category-pages","status":"publish","type":"gd_place","link":"https:\/\/wpgeodirectory.com\/documentation\/article\/advanced-search\/customise-search-on-category-pages\/","title":{"rendered":"How to customise the search on GeoDirectory category pages"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">All category pages of a post type share one archive template, so the search bar on them is the same everywhere. By default, a search started from a category page searches the whole post type.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Remove the category filter from the search<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">With the Advanced Search add-on, the search fields for each post type are set at Places &gt; Settings &gt; Search. Remove the Categories field from the list and save. See <a href=\"https:\/\/wpgeodirectory.com\/documentation\/article\/advanced-search\/settings-overview-for-cpt-settings-search\/\">Settings Overview for CPT &gt; Settings &gt; Search<\/a> for the other field options.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Keep searches on a category page inside that category<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This needs a short snippet. It adds the current category to the search form as a hidden field when the form is shown on a category page, so the results only include listings in that category. Add it with the <a href=\"https:\/\/wpgeodirectory.com\/documentation\/article\/useful-plugins\/code-snippets-plugin\/\">Code Snippets plugin<\/a> or your child theme&#8217;s functions.php.<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-php\">add_action( &#039;geodir_search_hidden_fields&#039;, &#039;my_gd_search_current_category&#039; );\nfunction my_gd_search_current_category( $instance ) {\n\tif ( ! is_tax() || ! geodir_is_page( &#039;archive&#039; ) ) {\n\t\treturn;\n\t}\n\n\t$term = get_queried_object();\n\n\tif ( ! empty( $term-&gt;term_id ) &amp;&amp; substr( $term-&gt;taxonomy, -8 ) === &#039;category&#039; ) {\n\t\techo &#039;&lt;input type=&quot;hidden&quot; name=&quot;spost_category&#091;&#093;&quot; value=&quot;&#039; . absint( $term-&gt;term_id ) . &#039;&quot; \/&gt;&#039;;\n\t}\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If you only need a fixed category on one normal page, see <a href=\"https:\/\/wpgeodirectory.com\/documentation\/article\/code-snippets\/set-specific-category-in-search-bar-on-a-specific-page\/\">Set Specific Category in Search Bar on a Specific Page<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Hide the Near field<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To hide the Near field in one search bar, tick <em>Hide Near Search Input<\/em> in the GD &gt; Search block, or add <code>hide_near_input=&quot;1&quot;<\/code> to the shortcode. That hides it wherever that search bar appears.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To hide it only on some category pages, use CSS. WordPress adds a <code>term-{slug}<\/code> class to the body on category pages, and the Near field sits in a <code>.gd-search-field-near<\/code> wrapper. Replace <em>online-services<\/em> with your category slug:<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-css\">.term-online-services .gd-search-field-near {\n    display: none;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>All category pages of a post type share one archive template, so the search bar on them is the same everywhere. By default, a search started from a category page searches the whole post type. Remove the category filter from the search With the Advanced Search add-on, the search fields for each post type are [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"article\/tags":[],"article\/categories":[213,400],"class_list":["post-2524","gd_place","type-gd_place","status-publish","hentry","gd_placecategory-extensions-features","gd_placecategory-advanced-search"],"_links":{"self":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/2524","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article"}],"about":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/types\/gd_place"}],"author":[{"embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/comments?post=2524"}],"version-history":[{"count":1,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/2524\/revisions"}],"predecessor-version":[{"id":2702,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/2524\/revisions\/2702"}],"wp:attachment":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/media?parent=2524"}],"wp:term":[{"taxonomy":"gd_place_tags","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/tags?post=2524"},{"taxonomy":"gd_placecategory","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/categories?post=2524"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}