Last active
January 12, 2018 10:11
-
-
Save IronGhost63/584ec50cbef2baeb3796538c8ae7b99b to your computer and use it in GitHub Desktop.
Show posts which have search term in title first
This file contains 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
<?php | |
function wp63_alter_search_weight($args, $query){ | |
global $wpdb; | |
if( $query->query_vars['search_terms'][0] ){ | |
$args['orderby'] = 'CASE WHEN `'.$wpdb->posts.'`.`post_title` LIKE "%'.$query->query_vars['search_terms'][0].'%" THEN 1 ELSE 0 END DESC' ; | |
} | |
return $args; | |
} | |
add_action("posts_clauses_request", "wp63_alter_search_weight", 50, 2); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment