Layout Builder Search Result Page

I’ve built a custom layout for a search results page.

I’ve also added paging to the bottom of the results. The issue is that while the paging seems to show correctly it does not matter what page I select I get the first set of results from page 1.

Seems I have sorted this out.

Now still struggling with the order of the search results. They should be ordered by date. In the developer tools it says it is ordered by date but the order seems to be completely random.

Glad to hear you got it working! Unfortunately we don’t have a way to reorder the search results in Pro. They are just being output the way WordPress returns them. It’s pretty much the same if you created a custom search results template for a theme - you’re just creating markup/styling for the results but WordPress determines how they are generated.

There are probably some ways to re-order the WordPress search results with custom code, at which point it would take effect on your Layout as well.

Thanks. I’m sorted. For anyone else wondering it is just a matter of filtering the results.

This worked for me.

add_filter('posts_orderby','sort_search_by_date',10,2);

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

if(!is_admin() && is_search()) 
    $orderby =  $wpdb->prefix . "posts.post_date DESC";

  return  $orderby;
}
}
1 Like

Nice! Thanks @urchindesign for sharing this.