Support

Account

Home Forums General Issues Query posts where relationship field value is inside an array Reply To: Query posts where relationship field value is inside an array

  • Thank you, but it doesn’t work like i need. Code below works like a charm for me:

    if (isset($_POST['regions'])) {
            $regions_arr = $_POST['regions']; // [319, 315]
            foreach ($regions_arr as $id) {
                $region_relations[] = array(
                    'key' => 'product-region',
                    'value' => "$id",
                    'compare' => 'LIKE'
                );
            }
    
            $args['meta_query'][] = array(
                array_merge(array('relation' => 'AND'), $region_relations)
            );
        }