I already asked this question before but it’s been closed due to expiration.
I want to display listings in a random order, instead of date eg. For example they choose a tag, than it should randomly display all listings with that tag. If they select a category, than it displays all listings from the selected category in random order.
You said it might be possible to customizations.
I found this snipped here which works for normal blog posts:
add_action('pre_get_posts','alter_query');
function alter_query($query){
if ($query->is_main_query() && is_home())
$query->set('orderby', 'rand'); //Set the order to random
}
Could you please help me adjust this code to make it work for posts please?
It still shows the same listings no matter how often I refresh the page. Is it possible to make the random order work for shortcodes as well?
As a result with my specific shortcode it should choose 12 random listings out of all listings that have the category with id 36. But it should work for every shortcode no matter the category id or even when I don’t add a category at all.
Could you please provide me a code that works for this scenario as well?
Thank you for your help and efforts. Appreciate it.
Sorry, there’s no simple code snippet for this, it would require a custom implementation. If customizations beyond the available features are required for your site, please consider hiring someone for custom work https://fvrr.co/32e7LvY