Wordpress - How can I change the admin search posts fields?
It is possible, but you'll have to play a little bit with the actual query. As always, the furious posts_clauses
filter comes to action:
function wpse_alter_posts_search( $pieces )
{
global $wpdb;
// Make the input save
$search_string = like_escape( $_GET['s'] );
// Your new WHERE clause
$where = $wpdb->prepare(
"$wpdb->postmeta.%s LIKE %s",
'YOUR_COLUMN', // Should match your col name 1)
"%{$search_string}%"
);
// Not sure if this exactly the same on your install 2)
$pieces['where'] = str_replace( 'AND (((', "AND ((({$where} ", $pieces['where'] );
return $pieces;
}
add_filter( 'posts_clauses', 'wpse_alter_posts_search' );
NOTES
- Could be that you need to unserialize some parts to be search able.
- You better simply dump the
$pieces
to take a look into them, before altering the query (right after the$search_string
was received).