Reputation: 71
please can you help me how do action which search posts only by title and sort by title. I dont want change query search in include file query.php.
function sort_searchresult_by_title($k){
if(is_search()){
$k->query_vars['orderby'] = 'title';
$k->query_vars['order'] = 'ASC';
// some code for change search logic
}
}
add_action('pre_get_posts','sort_searchresult_by_title');
Thank you, P. V.
Upvotes: 0
Views: 3172
Reputation: 7361
By default, WordPress constructs the search query to look in the post_title
and post_content
fields. You can change it by hooking into the posts_search
filter, and creating a new SQL clause there.
Did you know that there is a WordPress Stack Exchange, specific to all WordPress-related questions?
Upvotes: 1