Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Random Results
This topic contains 6 replies, has 2 voices, and was last updated by kkmarch7 7 years, 11 months ago.
- AuthorPosts
- September 22, 2015 at 9:59 am #5994
Hi!
Is there any way to have the search results populate randomly?
Thank you for your time.
September 23, 2015 at 12:39 pm #6011Hi!
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.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
September 23, 2015 at 11:29 pm #6017Hi 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 #6023Hi!
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:
ORDER BY priority DESC, relevance DESC, " . $wpdb->posts . "." . $orderby . "
change that line to:
ORDER BY RAND()
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.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
October 5, 2015 at 4:58 am #6112Hi 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.
Attachments:
You must be logged in to view attached files.October 5, 2015 at 9:08 am #6116Oh, 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:
if (count($all_pageposts) > 0) {
and replace it with this negative statement:
if (0) {
So it becomes inactive. Then the go to line 384:
ORDER BY priority DESC, relevance DESC, " . $wpdb->posts . "." . $orderby . "
and change that to:
ORDER BY RAND()
If I’m correct, this should work 🙂
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
October 6, 2015 at 5:01 am #6138Thank you this worked!
- AuthorPosts
You must be logged in to reply to this topic.