按字符串中的元值“价格”排序

时间:2019-03-30 22:37:00

标签: php wordpress

事实证明,我想订购一个称为“ price”的元值,该元值与“ description”等其他字词相邻。每个值都有其值。我试图用“ 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 :(得分:0)

我的元数据是这样的:

a:10:{s:9:“ destacado”; s:9:“ destacado”; s:6:“ precio”; s:4:“ 4389”; s:3:“ sub”; s: 9:“含税”; s:4:“徽标”; s:4:“ Bhhh”; s:8:“ potencia”; s:1:“ 4”; s:8:“ llamada1”; s: 5:“ Jjjjj”; s:4:“ url1”; s:4:“ Jjjj”; s:4:“ desc”; s:3:“ Jjj”; s:8:“ llamada2”; s:2: “ Jj”; s:4:“ url2”; s:3:“ Jjj”;}