开发者

How search by title in Wordpress?

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 inc开发者_运维知识库lude 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.


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜