Uxio
November 14, 2023, 8:59pm
1
Is it possible that when searching for accommodations with certain characteristics the system returns the accommodations that comply with the highlighted ones first and then the rest randomly? So that you don’t always see the same order so that all the ads have the same chance of being seen at some time?
andrii
November 15, 2023, 8:55am
3
Hi,
Please check the solutions in these topics:
Found the solution, trying now to do the same with the search results, will update if succeeded.
// Initialize session if not already started
if (!session_id()) {
session_start();
}
add_filter(
'posts_orderby',
function($orderby, $query){
if ( $query->get( 'post_type' ) === 'hp_listing' && is_post_type_archive('hp_listing') && empty($_GET['_sort']) ) {
if (isset($_SESSION['listing_seed'])) {
$seed = $_SESSION['listing_seed'];
} else…
This code randomizes the listings if you go to all categories from the homepage, but if you click on an individual category from the homepage, it doesn’t perform the function.
add_filter(
'posts_orderby',
function($orderby, $query){
if ( $query->get( 'post_type' ) === 'hp_listing' && is_post_type_archive('hp_listing') && empty($_GET['_sort']) ) {
$orderby = 'RAND()';
}
return $orderby;
},
10,
2
);
Is there an alternative that would solve this problem? Thank yo…
Please note that it can require further customization.
I hope this is helpful to you.
system
Closed
December 15, 2023, 8:55am
4
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.