Answer the question
In order to leave comments, you need to log in
Wordpress meta_query how to correctly build a query to find in an array?
Good afternoon friends, I have an items element in wp_postmeta , an array of various elements is written into it.
If you look at the database, it looks something like this: a:1:{i:0;a:2:{s:2:"id";s:4:"6592";s:13:"customization";s:3 :"off";}}
What I'm trying to do is:
$args = array(
'posts_per_page' => -1,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'items',
'value' => '6592',
'meta_compare' => 'LIKE'
)
)
);
$query = new WP_Query($args);
Answer the question
In order to leave comments, you need to log in
unfortunately, it
would be better to change the data storage structure
As an option in the oak way:
$args = array( 'posts_per_page' => -1);
$query = new WP_Query($args);
while ($recent->have_posts()) {
$recent->the_post();
$items = get_post_meta(get_the_ID(), 'items', true);
//тут проверяешь $items на вхождение нужного параметра, если подходит тов ывводим
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question