У меня есть пользовательский тип сообщения «оборудование» и мета-ключ «серийный».Я хотел бы запросить серийное поле postmeta в wp-admin.
У меня есть "пользовательская" страница поиска, настроенная на https://mydomain/wp-admin/edit.php?post_type=equipment
Все это работает нормально, проблема в том, что я хотел бы запросить серийный / модельный постмета по умолчанию.Моя пользовательская функция, кажется, не имеет никакого эффекта.Он проверяет истину, потому что я получаю массив $ query, который выводится на экран.
add_action( 'pre_get_posts', 'admin_search_meta' );
function admin_search_meta( $query ) {
$type = get_query_var('post_type');
if ( $query->is_main_query() && is_admin() && $type == "equipment") {
//$query->set( 'posts_per_page', '-1' );
$meta_query_args = array(
'relation' => 'AND',
array(
'key' => 'serial',
'value' => get_query_var('s'),
'compare' => 'REGEXP'
),
array(
'key' => 'model',
'value' => get_query_var('s'),
'compare' => 'REGEXP'
)
);
$query->set( 'meta_query', $meta_query_args );
print_r($query);
}
}
Вот вывод print_r ($ query);
WP_Query Object ([query] => Array ([m] => 0 [s] => Z452514A [paged] => 1 [order] => [orderby] => [post_type] => equipment [posts_per_page]=> 200 [post_status] => [perm] =>) [query_vars] => Массив ([m] => 0 [s] => Z452514A [paged] => 1 [order] => [orderby] => [post_type] => equipment [posts_per_page] => 200 [post_status] => [perm] => [error] => [p] => 0 [post_parent] => [subpost] => [subpost_id] => [attachment]=> [attachment_id] => 0 [имя] => [статические] => [имя_страницы] => [page_id] => 0 [секунда] => [минута] => [час] => [день] => 0[monthnum] => 0 [year] => 0 [w] => 0 [category_name] => [tag] => [cat] => [tag_id] => [author] => [author_name] => [feed] => [tb] => [meta_key] => [meta_value] => [preview] => [предложение] => [title] => [fields] => [menu_order] => [embed] => [category__in] => Array () [category__not_in]=> Array () [category__and] => Array () [post__in] => Array () [post__not_in] => Array () [post_name__in] => Array () [tag__in] => Array () [tag__not_in] =>Array () [tag__and] => Array () [tag_slug__in] => Array () [tag_slug__and] => Array () [post_parent__in] => Array () [post_parent__not_in] => Array () [author__in] => Array () [author__not_in] => Array () [meta_query] => Array ([отношение] => AND [0] => Array ([ключ] => последовательный [значение] => Z452514A [сравнить] => REGEXP) [1] => Массив ([ключ] => двигатель [значение] => Z452514A [сравнить] => REGEXP))) [tax_query] => Объект WP_Tax_Query ([запросы] => Массив () [отношение] => И [таблица_aliases: protected] => Array () [queried_terms] => Array () [primary_table] => [primary_id_column] =>) [meta_query] => [date_query] => [post_count] => 0 [current_post] => -1[in_the_loop] => [comment_count] => 0 [current_comment] => -1 [found_posts] => 0 [max_num_pages] => 0 [max_num_comment_pages] => 0 [is_single] => [is_preview] => [is_page]=> [is_archive] => [is_date] => [is_year] => [is_month] => [is_day] => [is_time] => [is_author] => [is_category] => [is_tag] => [is_tax]=> [is_search] => 1 [is_feed] => [is_comment_feed] => [is_trackback] => [is_home] => [is_404] => [is_embed] => [is_paged] => [is_admin] => 1 [is_attachment] => [is_singular] => [is_robots] => [is_posts_page] => [is_post_type_archive] => [query_vars_hash: WP_Query: private] => d36484fc4412f4eec2df43a812ee8d7a [query_s_Wirect_Words>: WP_Query: private] => [compat_fields: WP_Query: private] => Массив ([0] => query_vars_hash [1] => query_vars_changed) [compat_methods: WP_Query: private] => Array ([0] => init_query_flags [1] => parse_tax_query))