Last active
February 9, 2018 12:53
-
-
Save ferourives/dd0184576205b41399c106f37a0f4e0d to your computer and use it in GitHub Desktop.
function to order search results by title
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //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