A
A
av_tyschenko2016-03-21 18:20:16
WordPress
av_tyschenko, 2016-03-21 18:20:16

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);

But alas, he does not find anything. How to build a query correctly?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2016-03-21
@dimasmagadan

unfortunately, it
would be better to change the data storage structure

I
Ivan Kozlov, 2016-03-22
@trampick

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 question

Ask a Question

731 491 924 answers to any question