Random Results

This topic contains 6 replies, has 2 voices, and was last updated by kkmarch7 kkmarch7 8 years, 6 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #5994
    kkmarch7
    kkmarch7
    Participant

    Hi!

    Is there any way to have the search results populate randomly?

    Thank you for your time.

    #6011
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    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 :)


    #6017
    kkmarch7
    kkmarch7
    Participant

    Hi 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.

    #6023
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    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 :)


    #6112
    kkmarch7
    kkmarch7
    Participant

    Hi 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.
    #6116
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Oh, 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 :)


    #6138
    kkmarch7
    kkmarch7
    Participant

    Thank you this worked!

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.