想通了。
function atom_search_where($where){
global $wpdb;
if (is_search())
$where .= "OR (t.name LIKE '%".get_search_query()."%' AND {$wpdb- >posts}.post_status = 'publish')";
return $where;
}
function atom_search_join($join){
global $wpdb;
if (is_search())
$join .= "LEFT JOIN {$wpdb->term_relationships} tr ON {$wpdb->posts}.ID = tr.object_id INNER JOIN {$wpdb->term_taxonomy} tt ON tt.term_taxonomy_id=tr.term_taxonomy_id INNER JOIN {$wpdb->terms} t ON t.term_id = tt.term_id";
return $join;
}
function atom_search_groupby($groupby){
global $wpdb;
// we need to group on post ID
$groupby_id = "{$wpdb->posts}.ID";
if(!is_search() || strpos($groupby, $groupby_id) !== false) return $groupby;
// groupby was empty, use ours
if(!strlen(trim($groupby))) return $groupby_id;
// wasn't empty, append ours
return $groupby.", ".$groupby_id;
}
add_filter('posts_where','atom_search_where');
add_filter('posts_join', 'atom_search_join');
add_filter('posts_groupby', 'atom_search_groupby');
什麼讓你覺得你應該能夠按作者搜索?看到這個:http://wordpress.stackexchange.com/questions/29561/possible-to-search-by-author-name-with-default-wordpress-search-function和這個:https://wordpress.org/support/topic/display-all-user-posts-using-search-parameter-not-author-templatequery_posts –
@cale_b b/c我已經可以搜索多個用戶。我只是稱它爲作者。用戶編寫帖子,帖子可以通過查詢中的關鍵詞進行搜索。 – diwao11
這並沒有說明你的問題。你的問題沒有提到插件或自定義代碼。在沒有自定義代碼的情況下,** WordPress在搜索時不會包含「作者」(或「用戶」),因此它不會*查找給定作者的帖子。 –