• Hello everybody!
    Need help here.. I tried and sought a lot of thing, but without success..

    I’m using a plugin that creates for each new post a custom field that is filled with an array.

    This array contains some important values (like some relationships), and now, I’m trying to make a new WP_Query to filter my post with this information.

    Reading the codex, I saw that i can make a custom query using meta_keys:

    $query = new WP_Query( array(
       'meta_key' => '_color',
       'meta_value' => 'blue',
       'meta_compare' => '='
     ) );

    but if the key and value are inside an array?

    This code below is wrong.. any ideas?

    $query = new WP_Query( array(
       'meta_key' => '_color',
       'meta_value' => array(
          'meta_key' => 'price',
          'meta_value' =>'5',
       )
       'meta_compare' => '='
     ) );

    my custom field (doing the get_post_meta($post->ID, ‘_color ‘) in a print_r):

    print_r(get_post_meta($post->ID, '_color'));

    Array
    (
        [0] => Array
            (
                [_code] => 4860
                [_name] => blue
                [_price] => 5
            )
    )

    retrieve these values in a loop, after a normal query, isn’t a problem.. I just put these values in a string, and read the array.

    in my case, for e.g., my try is to make a query with only the posts that have the key “_price” with the value “5”;

    thanks in advance!!

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘custom query using keys of a custom field array’ is closed to new replies.