我认为您需要添加一个posts\\u连接过滤器,以连接posts和postmeta表。
此链接应有帮助:http://codex.wordpress.org/Custom_Queries, 特别是这段示例代码:
add_filter(\'posts_join\', \'geotag_search_join\' );
add_filter(\'posts_where\', \'geotag_search_where\' );
function geotag_search_join( $join )
{
global $geotag_table, $wpdb;
if( is_search() ) {
$join .= " LEFT JOIN $geotag_table ON " .
$wpdb->posts . ".ID = " . $geotag_table .
".geotag_post_id ";
}
return $join;
}
function geotag_search_where( $where )
{
if( is_search() ) {
$where = preg_replace(
"/\\(\\s*post_title\\s+LIKE\\s*(\\\'[^\\\']+\\\')\\s*\\)/",
"(post_title LIKE $1) OR (geotag_city LIKE $1) OR (geotag_state LIKE $1) OR (geotag_country LIKE $1)", $where );
}
return $where;
}