未经测试,但应满足以下条件:
add_action( \'posts_clauses\', \'wpse110779_filter_admin_search\', 10, 2 );
function wpse110779_filter_admin_search( $pieces, $query ){
global $wpdb;
//Check if this is the main query,and is a search on the admin screen
if( $query->is_search() & $query->is_admin() && $query->is_main_query() ){
//Collect post types & search term
$post_types = $query->get(\'post_type\');
$search = $query->get(\'s\');
//Check if query is for \'my-cpt\' post type
if( \'my-cpt\' == $post_types
|| ( is_array( $post_types ) && in_array( \'my-cpt\', $post_types ) )
){
//Set up meta query
$meta_query = array( array(
\'key\' => \'my_key\',
\'value\' => $search,
\'compare\' => \'LIKE\'
));
//Generate sql
$meta_sql = get_meta_sql( $meta_query, \'post\', $wpdb->posts, \'ID\', $query );
$pieces[\'join\'] . = " ". $meta_sql[\'join\'];
$pieces[\'where\'] . = " OR (" . $meta_sql[\'where\'] .")";
}
}
return $pieces;
}
请注意这一点
completely 未经测试,但应在原则上起作用,至少可以让您开始。