2016-01-15 37 views
0

當我按他們的名字搜索用戶時,他們的所有帖子都顯示在儀表板中。當我搜索同一個用戶並添加他們的姓氏時,它根本不顯示。不知道爲什麼只發生這個作者。我已將所有設置與其他寫有帖子的用戶進行了相同的設置。Wordpress搜索查詢沒有返回用戶

這是我的第一個搜索URL和查詢,它返回此用戶寫的所有帖子。 http://trochia.org/?s=dani

當我添加她的姓氏時,沒有結果。 http://trochia.org/?s=dani+nichols

這是另一個用戶,沒有問題只有名字或與名字和姓氏的組合。 http://trochia.org/?s=fred http://trochia.org/?s=fred+gladney

+0

什麼讓你覺得你應該能夠按作者搜索?看到這個: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 –

+0

@cale_b b/c我已經可以搜索多個用戶。我只是稱它爲作者。用戶編寫帖子,帖子可以通過查詢中的關鍵詞進行搜索。 – diwao11

+0

這並沒有說明你的問題。你的問題沒有提到插件或自定義代碼。在沒有自定義代碼的情況下,** WordPress在搜索時不會包含「作者」(或「用戶」),因此它不會*查找給定作者的帖子。 –

回答

0

想通了。

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');