lundi 5 octobre 2015

Query with meta key is serialized array

I've made a custom query containing a meta query but some fields are serialized arrays. Is there a way to get the value from that array? Everything I've tried so far won't work.

$query_args = array(
                    'post_type'         => 'yacht',
                    '_meta_or_tax'      => true,
                    'tax_query'         => array(
                        'relation'      => 'AND',
                        array(
                            'taxonomy'  => 'manufacturers',
                            'field'     => 'id',
                            'terms'     => $_GET['manufacturer']
                        ),
                        array(
                            'taxonomy'  => 'category',
                            'field'     => 'id',
                            'terms'     => $_GET['cat'],
                        )
                    ),
                    'posts_per_page'    => -1,
                    'meta_query'        => array(
                        'relation'      => 'AND',
                        array(
                         'key'          => 'yachts_length',
                         'value'        => array($_GET['min_length'], $_GET['max_length']),
                         'compare'      => 'BETWEEN',
                         'type'         => 'NUMERIC',
                        ),
                        array(
                         'key'          => 'yachts_price',
                         'value'        => array($_GET['min_price'], $_GET['max_price']),
                         'compare'      => 'BETWEEN',
                         'type'         => 'NUMERIC',
                        ),
                        array(
                         'key'          => 'yachts_year',
                         'value'        => array($_GET['min_year'], $_GET['max_year']),
                         'compare'      => 'BETWEEN',
                         'type'         => 'NUMERIC',
                        ),
                        array(
                         'key'          => 'yachts_fuel',
                         'value'        => $_GET['fuel'],
                         'compare'      => 'LIKE',
                        ),
                        array(
                         'key'          => 'yachts_cabins',
                         'value'        => $_GET['cabins'],
                         'compare'      => 'LIKE',
                         'type'         => 'NUMERIC',
                        ),
                        array(
                         'key'          => 'yachts_engine_type',
                         'value'        => $_GET['engine_type'],
                         'compare'      => 'LIKE',
                        ),
                        array(
                         'key'          => 'yachts_en',
                         'value'        => $_GET['engines'],
                         'compare'      => 'LIKE',
                         'type'         => 'NUMERIC',
                        ),
                        array(
                         'key'          => 'yachts_drive',
                         'value'        => $_GET['drive_type'],
                         'compare'      => 'LIKE',
                        ),
                    )
                );

                $yacht_query = new WP_Query( $query_args );

yachts_cabins, yachts_fuel, yachts_engine_type, yachts_en, yachts_type are serialized arrays.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire