Sólo tienes que añadirlo a tu plugin de funciones y cambiar el nombre del Post Type.
add_filter( 'posts_join', 'eliasgomez_search_join' );
function eliasgomez_search_join ( $join ) {
global $pagenow, $wpdb;
// I want the filter only when performing a search on edit page of Custom Post Type named "tu_post_type".
if ( is_admin() && 'edit.php' === $pagenow && 'tu_post_type' === $_GET['post_type'] && ! empty( $_GET['s'] ) ) {
$join .= 'LEFT JOIN ' . $wpdb->postmeta . ' ON ' . $wpdb->posts . '.ID = ' . $wpdb->postmeta . '.post_id ';
}
return $join;
}
add_filter( 'posts_where', 'eliasgomez_search_where' );
function eliasgomez_search_where( $where ) {
global $pagenow, $wpdb;
// I want the filter only when performing a search on edit page of Custom Post Type named "tu_post_type".
if ( is_admin() && 'edit.php' === $pagenow && 'tu_post_type' === $_GET['post_type'] && ! empty( $_GET['s'] ) ) {
$where = preg_replace(
"/\(\s*" . $wpdb->posts . ".post_title\s+LIKE\s*(\'[^\']+\')\s*\)/",
"(" . $wpdb->posts . ".post_title LIKE $1) OR (" . $wpdb->postmeta . ".meta_value LIKE $1)", $where );
}
return $where;
}
add_filter( 'posts_groupby', 'eliasgomez_search_group' );
function eliasgomez_search_group($groupby) {
global $pagenow, $wpdb;
if ( is_admin() && $pagenow == 'edit.php' && $_GET['post_type']=='tu_post_type' && $_GET['s'] != '' ) {
$groupby = "$wpdb->posts.ID";
}
return $groupby;
}
I have created a custom post type and have attached some custom fields to it. Now I would like to the search that authors can perform on the custom post list screen (in the admin backend) to also be
Origen: Extending the search context in the admin list post screen