By default WP sorts newest Posts at the top of search results.

I’m using WP Posts as a Members list for a sewing referral group. The search results need to be in order of seniority, so the oldest posts need to appear at the top of the search results—the opposite of the default sort order.

I also have a Custom Field for member numbers, so I could easily use that instead of the post date for search result order.

I'm using a child theme, have no problem adding code to the functions.php file. I am NOT a coder so don't know how to do this on my own.

Thank you!

1 Answer 1


You can use the action hook posts_orderby in your child themes functions.php:

function changeSearchSort( $orderby, $query ){
    global $wpdb;

    if(!is_admin() && is_search()) {
        $orderby =  $wpdb->prefix."posts.post_date ASC";
    return  $orderby;
  • Thank you so much, this is what I was looking for!
    – Deb T
    Jun 7, 2019 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.