这可能有效,但尚未测试。首先添加此项以加入Posteta表:
add_filter( \'posts_join\', \'search_filters_join\', 501, 2 );
function search_filters_join( $join, $query ) {
global $wpdb;
if ( empty( $query->query_vars[ \'post_type\' ] ) || $query->query_vars[ \'post_type\' ] !== \'product\' ) {
return $join; // skip processing
}
if ( ($this->is_ajax_search() || $this->is_search_page()) && !is_admin() ) {
$join .= " INNER JOIN $wpdb->postmeta AS customsearch ON ( $wpdb->posts.ID = customsearch.post_id )";
}
return $join;
}
然后修改
$search
-foreach循环中的变量,以包括以下内容(此示例显示
_sku
, 只需添加
_author
给另一个人
OR
部分(如果您还想搜索):
$search .= "{$searchand} (($wpdb->posts.post_title LIKE \'{$n}{$term}{$n}\') OR (customsearch.meta_key=\'_sku\' AND customsearch.meta_value LIKE \'{$n}{$term}{$n}\'))";