我想在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);

最佳答案

我找到了解决方案:

$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');


对于那些有同样问题的人
谢谢大家

08-19 05:29