Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Random Results
- This topic has 6 replies, 2 voices, and was last updated 10 years, 8 months ago by
kkmarch7.
-
AuthorPosts
-
September 22, 2015 at 9:59 am #5994
kkmarch7
ParticipantHi!
Is there any way to have the search results populate randomly?
Thank you for your time.
September 23, 2015 at 12:39 pm #6011Ernest Marcinko
KeymasterHi!
Do you mean random results order, or the user types in something and just random results should appear?
There is no setting for either, but if you let me know I might be able to suggest something.
September 23, 2015 at 11:29 pm #6017kkmarch7
ParticipantHi Ernest,
I would like the order of the results to be random. Do you have a suggestion on how I could make this happen?
Thank you for your time.
September 24, 2015 at 10:17 am #6023Ernest Marcinko
KeymasterHi!
Only with a minor modification to the code, there is not other way unfortunately.
If you open up the wp-content/plugins/ajax-search-pro/includes/search/search_content.class.php file and scroll down to line 607, where you should see this:
[code]ORDER BY priority DESC, relevance DESC, " . $wpdb->posts . "." . $orderby . "[/code]
change that line to:
[code]ORDER BY RAND()[/code]
That should do it.
Please not that this solution is not update-proof, so once you update, you need to do this again. Also, make sure to do tests with a few phrases, random ordering might be a resource-heavy operation in some cases.
October 5, 2015 at 4:58 am #6112kkmarch7
ParticipantHi Ernest
I was wondering if I understood your suggestion correctly.
Line 607 is as follows
} else if ($orderby == ‘post_date ASC’) {Do I replace it with the following?
} else if ($orderby == ORDER BY RAND() {Thank you for your time.
October 5, 2015 at 9:08 am #6116Ernest Marcinko
KeymasterOh, you are using a different version than what I’m looking at and I forgot about the secondary ordering as well.
For the correct solution, first find line 602:
[code]if (count($all_pageposts) > 0) {[/code]
and replace it with this negative statement:
[code]if (0) {[/code]
So it becomes inactive. Then the go to line 384:
[code]ORDER BY priority DESC, relevance DESC, " . $wpdb->posts . "." . $orderby . "[/code]
and change that to:
[code]ORDER BY RAND()[/code]
If I’m correct, this should work 🙂
October 6, 2015 at 5:01 am #6138kkmarch7
ParticipantThank you this worked!
-
AuthorPosts
- You must be logged in to reply to this topic.