{"id":2939,"date":"2026-10-20T08:40:00","date_gmt":"2026-10-20T07:40:00","guid":{"rendered":"https:\/\/wpgeodirectory.com\/documentation\/article\/sort-search-results-2\/"},"modified":"2026-10-20T08:40:00","modified_gmt":"2026-10-20T07:40:00","slug":"sort-search-results-2","status":"publish","type":"gd_place","link":"https:\/\/wpgeodirectory.com\/documentation\/article\/core-features\/sort-search-results-2\/","title":{"rendered":"How to sort GeoDirectory search results"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">GeoDirectory sorts search results automatically and does not show a sort dropdown on the search page. You can still change the order with a URL parameter or a small snippet.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How search results are ordered<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If the visitor searched near a location, results are ordered by distance, nearest first.<\/li>\n\n\n\n<li>If there is no location but there is a keyword, results are ordered by best match for that keyword.<\/li>\n\n\n\n<li>With neither, the default sort for the post type is used. You set that in Places > Settings > Sorting.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The sort options you set up in Places > Settings > Sorting appear on category and archive pages, not on the search page. See <a href=\"https:\/\/wpgeodirectory.com\/documentation\/article\/core-features\/changing-or-adding-new-sorting-options\/\">changing or adding new sorting options<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Sort with the sort_by parameter<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The search page accepts a <code>sort_by<\/code> parameter. Add it to a search URL and the results use that order instead, for example <code>&amp;sort_by=high_rating<\/code>. Values you can use include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>high_rating<\/code> for highest rating<\/li>\n\n\n\n<li><code>high_review<\/code> for most reviews<\/li>\n\n\n\n<li><code>latest<\/code> for newest first<\/li>\n\n\n\n<li><code>az<\/code> and <code>za<\/code> for title order<\/li>\n\n\n\n<li><code>post_modified_desc<\/code> for recently updated<\/li>\n\n\n\n<li><code>random<\/code><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Add a sort dropdown to the search bar<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This snippet adds a &#8220;Sort by&#8221; select to the GD > Search bar, so visitors choose the order before they search. Add it with a code snippets plugin.<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-php\">add_action( &#039;geodir_before_search_button&#039;, function() {\n\t$current = isset( $_REQUEST&#091;&#039;sort_by&#039;&#093; ) ? sanitize_text_field( wp_unslash( $_REQUEST&#091;&#039;sort_by&#039;&#093; ) ) : &#039;&#039;;\n\t$options = array(\n\t\t&#039;&#039;            =&gt; __( &#039;Best match&#039;, &#039;geodirectory&#039; ),\n\t\t&#039;high_rating&#039; =&gt; __( &#039;Highest rating&#039;, &#039;geodirectory&#039; ),\n\t\t&#039;high_review&#039; =&gt; __( &#039;Most reviews&#039;, &#039;geodirectory&#039; ),\n\t\t&#039;latest&#039;      =&gt; __( &#039;Latest&#039;, &#039;geodirectory&#039; ),\n\t\t&#039;az&#039;          =&gt; __( &#039;A-Z&#039;, &#039;geodirectory&#039; ),\n\t);\n\n\techo &#039;&lt;div class=&quot;col-auto&quot;&gt;&lt;select name=&quot;sort_by&quot; class=&quot;form-select form-control&quot; aria-label=&quot;Sort by&quot;&gt;&#039;;\n\tforeach ( $options as $value =&gt; $label ) {\n\t\techo &#039;&lt;option value=&quot;&#039; . esc_attr( $value ) . &#039;&quot;&#039; . selected( $current, $value, false ) . &#039;&gt;&#039; . esc_html( $label ) . &#039;&lt;\/option&gt;&#039;;\n\t}\n\techo &#039;&lt;\/select&gt;&lt;\/div&gt;&#039;;\n} );<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Leaving it on &#8220;Best match&#8221; keeps the automatic order described above, including nearest first when a location is entered.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>GeoDirectory sorts search results automatically and does not show a sort dropdown on the search page. You can still change the order with a URL parameter or a small snippet. How search results are ordered The sort options you set up in Places > Settings > Sorting appear on category and archive pages, not on [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"","ping_status":"closed","template":"","meta":{"footnotes":""},"article\/tags":[],"article\/categories":[421,213],"class_list":["post-2939","gd_place","type-gd_place","status-publish","hentry","gd_placecategory-core-features","gd_placecategory-extensions-features"],"_links":{"self":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/2939","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=2939"}],"version-history":[{"count":0,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/2939\/revisions"}],"wp:attachment":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/media?parent=2939"}],"wp:term":[{"taxonomy":"gd_place_tags","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/tags?post=2939"},{"taxonomy":"gd_placecategory","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/categories?post=2939"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}