{"id":967,"date":"2025-03-24T14:28:09","date_gmt":"2025-03-24T14:28:09","guid":{"rendered":"https:\/\/wpgeodirectory.com\/documentation\/article\/how-to-change-the-default-algorithm-for-sort-by-ratings\/"},"modified":"2025-04-03T15:24:30","modified_gmt":"2025-04-03T14:24:30","slug":"how-to-change-the-default-algorithm-for-sort-by-ratings","status":"publish","type":"gd_place","link":"https:\/\/wpgeodirectory.com\/documentation\/article\/code-snippets\/how-to-change-the-default-algorithm-for-sort-by-ratings\/","title":{"rendered":"How to Change the Default Algorithm for &#8220;Sort by Ratings&#8221;?"},"content":{"rendered":"\n<p>By default, GeoDirectory uses a weighted algorithm based on the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Bayesian_average\">Bayesian Average Rating<\/a> system to sort listings by ratings.&nbsp;<\/p>\n\n\n\n<div class=\"wp-block-blockstrap-blockstrap-widget-alert d-flex align-items-center fade show alert alert-info mb-3\" role=\"alert\"><span class=\"fas fa-info-circle me-2\"><\/span><span class=\"flex-grow-1\">The biggest advantage of our algorithm is that it is smart enough to <strong>prevent a listing with just one 5-star rating from appearing above another rating with, say, seventy 5-star and two 4-star ratings.<\/strong> If we were to sort listings by average ratings only, a single 5-star will yield an average of &#8220;5&#8221;, whereas a rating with seventy 5-stars but just one 4-star will have an average lesser than &#8220;5&#8221;.<\/span><\/div>\n\n\n\n<p>However, if for some reason you do not wish to use the Bayesian Average for sorting listings, you can disable it using the following code snippet.&nbsp;<\/p>\n\n\n\n<div class=\"wp-block-blockstrap-blockstrap-widget-alert d-flex align-items-center fade show alert alert-info mb-3\" role=\"alert\"><span class=\"fas fa-info-circle me-2\"><\/span><span class=\"flex-grow-1\">We recommend using the <a href=\"https:\/\/wpgeodirectory.com\/documentation\/article\/useful-plugins\/code-snippets-plugin\/\">Code Snippets plugin<\/a> to add PHP snippets to your site.<\/span><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Code Snippet<\/h2>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-php\">\/**\n* Disable Bayesian average method to sort by ratings.* \n* See https:\/\/www.google.com\/search?q=bayesian+rating+sorting\n*\/\nfunction gd_snippet_200611_disable_use_bayesian( $use_bayesian = true, $table = &#039;&#039; ) {\n\treturn false;\n\t}\nadd_filter( &#039;geodir_use_bayesian&#039;, &#039;gd_snippet_200611_disable_use_bayesian&#039;, 10, 2 );\nadd_filter( &#039;gd_use_bayesian&#039;, &#039;gd_snippet_200611_disable_use_bayesian&#039;, 10, 2 );<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>By default, GeoDirectory uses a weighted algorithm based on the Bayesian Average Rating system to sort listings by ratings.&nbsp; However, if for some reason you do not wish to use the Bayesian Average for sorting listings, you can disable it using the following code snippet.&nbsp; Code Snippet<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"article\/tags":[828,829],"article\/categories":[211,433],"class_list":["post-967","gd_place","type-gd_place","status-publish","hentry","gd_place_tags-sort-listings","gd_place_tags-sort-by-rating","gd_placecategory-tips-tricks-more","gd_placecategory-code-snippets"],"_links":{"self":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/967","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=967"}],"version-history":[{"count":0,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/967\/revisions"}],"wp:attachment":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/media?parent=967"}],"wp:term":[{"taxonomy":"gd_place_tags","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/tags?post=967"},{"taxonomy":"gd_placecategory","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/categories?post=967"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}