{"id":971,"date":"2025-03-24T14:28:10","date_gmt":"2025-03-24T14:28:10","guid":{"rendered":"https:\/\/wpgeodirectory.com\/documentation\/article\/set-specific-category-in-search-bar-on-a-specific-page\/"},"modified":"2025-04-03T15:24:31","modified_gmt":"2025-04-03T14:24:31","slug":"set-specific-category-in-search-bar-on-a-specific-page","status":"publish","type":"gd_place","link":"https:\/\/wpgeodirectory.com\/documentation\/article\/code-snippets\/set-specific-category-in-search-bar-on-a-specific-page\/","title":{"rendered":"Set Specific Category in Search Bar on a Specific Page"},"content":{"rendered":"\n<p>In some cases if you are writing a page or blog post referencing a specific category on your site, you may want to pre-set the selected category in your search bar, to do this you can add the below snippet using the <a href=\"https:\/\/wordpress.org\/plugins\/code-snippets\/\">Code Snippets<\/a> plugin.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/wpgeodirectory.com\/documentation\/wp-content\/uploads\/2025\/03\/file-kpx5n2utu5.png\" alt=\"\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-php\">add_filter( &#039;geodir_search_output_to_main_categories&#039;, &#039;_my_set_cat_search&#039;, 8, 3 );\nfunction _my_set_cat_search( $html, $cf, $post_type ){\n\tglobal $post;\n\t\n\tif( is_page() &amp;&amp; isset($post-&gt;ID) ){ \/\/ use is_page() for pages and is_single() for blog posts\n\t\tif( $post-&gt;ID == 1469 ){\/\/ page ID\n\t\t\t$_REQUEST&#091;&#039;spost_category&#039;&#093;&#091;&#093; = 3; \/\/ category ID\n\t\t}elseif( $post-&gt;ID == 1234 ){ \/\/ page ID\n\t\t\t$_REQUEST&#091;&#039;spost_category&#039;&#093;&#091;&#093; = 9; \/\/ category ID\n\t\t}\n\t}\n\t\n\treturn $html;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In some cases if you are writing a page or blog post referencing a specific category on your site, you may want to pre-set the selected category in your search bar, to do this you can add the below snippet using the Code Snippets plugin.&nbsp;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"article\/tags":[],"article\/categories":[211,433],"class_list":["post-971","gd_place","type-gd_place","status-publish","hentry","gd_placecategory-tips-tricks-more","gd_placecategory-code-snippets"],"_links":{"self":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/971","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=971"}],"version-history":[{"count":0,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/971\/revisions"}],"wp:attachment":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/media?parent=971"}],"wp:term":[{"taxonomy":"gd_place_tags","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/tags?post=971"},{"taxonomy":"gd_placecategory","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/categories?post=971"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}