WordPress.org

Ready to get started?Download WordPress

Forums

WP Ultimate Search
[resolved] Ordering search results (5 posts)

  1. bludrop
    Member
    Posted 1 year ago #

    Is there a way to edit the sort order of the search results (so that they display in a chronological order)? It seems like they are being displayed in a random order.

    http://wordpress.org/plugins/wp-ultimate-search/

  2. Bryce Corkins
    Member
    Posted 1 year ago #

    If you know a little bit about programming, the plugin supports creating a custom output template that uses a standard WordPress loop... then you can modify the result order and formatting any way you want. You can read about how to do this on the FAQ at http://mindsharelabs.com/

  3. bludrop
    Member
    Posted 1 year ago #

    I do have a custom template set up and tried a number of ways to customize the order of the loop [as well as modify another part of the output]. It didn't seem to be working the same way other loops work.

  4. Bryce Corkins
    Member
    Posted 1 year ago #

    It's a little bit different, but essentially the same concept. All of the results are stored in the $results variable. You can use var_dump($results); to see the contents. You can iterate through this array and re-order it based on the date value of the posts... there's a lot of information on google about array sorting.

    We will make this easier in the future... with options that allow you to set the default order for returned results, and eventually we want to have a way for users to re-order results as they conduct searches.

  5. bludrop
    Member
    Posted 1 year ago #

    Thanks.

    For those interested, I used usort to sort the array, which was inserted at the top of the results custom template file.

    <?php usort( $results, create_function('$a,$b', 'return strcmp($b->post_date, $a->post_date);') ); ?>

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic