I have the following custom search active in our WP admin for only administrators
add_action('pre_get_posts', 'query_custom_admin_search', 21 );
function query_custom_admin_search( $wp_query ) {
global $current_user;
if( is_admin() ) {
if (get_current_user_role()=="administrator"){
if ( $wp_query->query['post_type'] != "apartments" ){
return;
}else{
$custom_fields = array("city","state_county",);
$search_term = $wp_query->query_vars['s'];
if ( $search_term != '' ) {
$meta_query = array( 'relation' => 'OR' );
foreach( $custom_fields as $custom_field ) {
array_push( $meta_query, array(
'key' => $custom_field,
'value' => $search_term,
'compare' => 'LIKE'
));
}
$wp_query->set( 'meta_query', $meta_query );
};
return;
}
}else{
return;
}
}else{
return;
}
}
This searches custom meta keys that we need to check and it works great. The only problem is that the default search columns in the wp_posts table such as post_title seem to no longer be searched.
How can I do both in this query ?