WordPress.org

Ready to get started?Download WordPress

Forums

WP: multiple meta_query from array (3 posts)

  1. Julian Chaniolleau
    Member
    Posted 1 year ago #

    I wasted some hours on that…. to know how can i get multiple meta_query like :

    'meta_query' => array(
        'relation' => 'OR',
        array(
            'key' => 'mykey',
            'value' => 'value1',
            'compare' => '='
        ),
        array(
            'key' => 'mykey',
            'value' => 'value2',
            'compare' => '='
        ),
    )

    from a simple array like :

    $mykey = array( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 );

    I need to generate the meta_query automatically because the array is not always the same. Thank you by advance! Julian

    [No bumping. If it's that urgent, consider hiring someone.]

  2. vtxyzzy
    Member
    Posted 1 year ago #

    This may be what you want:

    'meta_query' => array(
        'relation' => 'OR',
        array(
            'key' => 'mykey',
            'value' => $mykey,
            'compare' => 'IN'
        ),
    )
  3. Julian Chaniolleau
    Member
    Posted 1 year ago #

    Yes thank you vtxyzzy !
    exactly that!

Topic Closed

This topic has been closed to new replies.

About this Topic