我想按clinic
排序的WordPress中显示clinic_price
个帖子类型(clinic_price
是诊所帖子类型的metabox)。如何使用wpdb
按价格ASC和DESC订购诊所?
我正在使用WP_Query
按价格对帖子进行排序,但它只显示其中一家诊所!
$service_meta_price = str_replace(' ', '_', strtolower($post->post_title) . ' price');
$args = array(
'post_status' => 'publish',
'post_type' => 'clinics',
'meta_key' => $service_meta_price,
'orderby' => 'meta_value_num',
'order' => 'DESC'
);
$clinics = new WP_Query($args);
答案 0 :(得分:0)
我找到了解决方法:
$service_meta_price = str_replace(' ', '_', strtolower($post->post_title) . '
$clinics = $wpdb->get_results('SELECT * from wp_posts LEFT JOIN wp_postmeta m1 on m1.post_id = wp_posts.ID AND m1.meta_key = $service_meta_price WHERE post_type = "clinics" OR post_type = "surgeons" ORDER BY meta_value DESC');
对于那些有相同问题的人 谢谢大家