Skip to content

Instantly share code, notes, and snippets.

Last active Aug 25, 2016
What would you like to do?
// return results in a forced order by post type, sub ordered by weight
function my_searchwp_query_orderby( $sql, $engine ) {
global $wpdb;
// we want to return all Pages first, followed by Posts
* MUST INCLUDE ___ALL___ ENABLED POST TYPES <--------------------------
return "ORDER BY FIELD({$wpdb->prefix}posts.post_type, 'page', 'post'), finalweight DESC, {$wpdb->prefix}posts.post_date DESC";
add_filter( 'searchwp_query_orderby', 'my_searchwp_query_orderby', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment