Skip to content

Instantly share code, notes, and snippets.

@ferourives
Last active February 9, 2018 12:53
Show Gist options
  • Select an option

  • Save ferourives/dd0184576205b41399c106f37a0f4e0d to your computer and use it in GitHub Desktop.

Select an option

Save ferourives/dd0184576205b41399c106f37a0f4e0d to your computer and use it in GitHub Desktop.
function to order search results by title
//Ordena busca pelo titulo
add_action( 'pre_get_posts', 'my_change_sort_order');
function my_change_sort_order($query){
if(is_search()):
//If you wanted it for the archive of a custom post type use: is_post_type_archive( $post_type )
//Set the order ASC or DESC
$query->set( 'order', 'ASC' );
//Set the orderby
$query->set( 'orderby', 'relevance' );
endif;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment