I want to expand the Wordpress admin panel search using this code.
function add_search_query_meta( $query )
{
if ( is_admin() || ! $query->is_main_query() || ! $query->is_search )
return;
$s = get_search_query();
$query->set( 'meta_query', [
'relation' => 'OR',
[
'meta_key' => '_company_inn',
'value' => $s,
'compare' => 'LIKE',
],
[
'meta_key' => '_company_phone',
'value' => $s,
'compare' => 'LIKE',
],
] );
$query->set( 'post_type', 'company' );
}
add_filter( 'pre_get_posts', 'add_search_query_meta' );
function modify_where_search_request( $where )
{
if ( is_admin() || ! is_main_query() || ! is_search() )
return $where;
global $wpdb;
$s = get_search_query();
$where = preg_replace(
[
"~ OR \({$wpdb->posts}.post_[^\s]+ (LIKE '(?:%|{[^}]+}){$s}(?:%|{[^}]+})')\)~i", // убираем поиск по контенту и цитате
"~AND\s+([\s(]+{$wpdb->wp_pn_companymeta}.meta_key)~i" // меняем AND условие мета-запроса на OR
],
[
'',
'OR $1'
],
$where
);
return $where;
}
add_action( 'posts_where_request', 'modify_where_search_request' );
Database structure:
Here are the keys I'm trying to access and get the value of:
I don't understand how to get these values through a standard search, help please..