admin管理员组文章数量:1316974
Hi the default wordpress search seems to be for "piano"
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID
FROM wp_posts
WHERE 1=1
AND (((wp_posts.post_title LIKE '%piano%')
OR (wp_posts.post_excerpt LIKE '%piano%')
OR (wp_posts.post_content LIKE '%piano%')))
AND wp_posts.post_type IN ('post', 'page', 'attachment')
AND (wp_posts.post_status = 'publish'
OR wp_posts.post_author = 5
AND wp_posts.post_status = 'private')
ORDER BY wp_posts.post_title LIKE '%piano%' DESC, wp_posts.post_date DESC
LIMIT 0, 25
however I need them all sorted by date first. My search results by date are skewed:
2020-10-25
2020-10-22
2020-10-20
2020-10-20
2020-10-16
2020-10-13
2020-10-10
2020-10-07
2020-10-06
2020-10-02
2020-09-30
2020-09-28
2020-09-02
2020-08-09
2020-07-21
2020-07-21
2020-05-21
2020-04-24
2020-03-06
2019-06-02 <- here it is skewed onwards
2019-06-01
2020-10-25
2020-10-24
2020-10-23
2020-10-23
So I asume it is because the SQL query sorts by title first.
So I tried this solution:
function changeSearchSort( $orderby, $query ){
global $wpdb;
if(!is_admin() && is_search()) {
$orderby = $wpdb->prefix."posts.post_date ASC";
}
return $orderby;
}
add_filter('posts_orderby','changeSearchSort',10,2);
from here How do I change WP search results order?
and it does not work.
I have tried this:
a) disabled all plugins
b) different themes
still not working.
Help appreciated
cheers
Ben
本文标签: sqlSearch results sort order failing set by date only
版权声明:本文标题:sql - Search results sort order failing: set by date only 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742019953a2414445.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论