Порядок по мета-значению "цена" в строке - PullRequest
0 голосов
/ 31 марта 2019

получается, что я хочу заказать мета-значение, называемое «цена», которое рядом с другими, как «описание» и т. Д. Каждое со своим значением.Я попытался отсортировать его с помощью "meta_value_num", но он не упорядочен правильно.

Вот выдержка из моего кода.

$sc = shortcode_atts(array('nopaging' = false, 'post_type' = 'tarifa', 'query' = '', 'registers' = '',
                            'category' = '', 'tag_name' = '', 'customprice' = 'tarifas', 'price' = '',
                            'power' = '', 'relation_operator' = '', 'meta_key' = 'tarifas',
                            'orderby' = 'meta_value_num', 'order' = 'DESC',), $atts);

$options = array('meta_key' = $sc['meta_key'], 'order_by' = $sc['orderby'], 'order' = $sc['order'],
                'category_name' = $sc['category'], 'post_type' = $sc['post_type'], 'posts_per_page' = $sc['registers'],);

if ($sc['price'] == '' and $sc['power'] == '') {
    $options['meta_query'] = array('relation' = 'AND', array('relation' = 'OR', array('key' = $sc['customprice'], 'value' = $sc['price'],
            'compare' => 'LIKE',), array('key' = $sc['customprice'], 'value' = $sc['power'], 'compare' = 'LIKE',),));
    $sc['power'] = "default";
    $sc['price'] = "default";
} else {
    $options['meta_query'] = array('relation' = 'AND', array('relation' = 'OR', array('key' = $sc['customprice'], 'value' = sprintf(':"%s";',
            $sc['price']), 'compare' = 'LIKE',), array('key' = $sc['customprice'], 'value' = sprintf(':"%s";',
            $sc['power']), 'compare' = 'LIKE',),));
}

$your_loop = new WP_Query($options);

1 Ответ

0 голосов
/ 31 марта 2019

Мое мета-значение таково:

а: 10: {s: 9: "destacado"; s: 9: "destacado"; s: 6: "Precio"; s: 4: "4389"; s: 3: "суб"; s: 9: "IVA вкл."; С: 4: "логотип"; с: 4: "Бххх"; с: 8: "потенция"; с: 1: "4"; с: 8: "ламада1"; с: 5: "JJJJJ"; s: 4: "url1"; s: 4: "JJJJ"; s: 4: "убывание"; s: 3: "Jjj"; s: 8: "llamada2"; s: 2: "Й"; s: 4: "URL2"; s: 3: "Jjj";}

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...