简体   繁体   中英

Wordpress: How to fetch record from wp_posts and wp_postmeta in desc order by meta_value?

I want to get record from wp_posts with multiple custom post and show in descending order by multiple meta value from wp_postmeta.meta_value.

Right now, I am using this query:

    $args = array(
        'numberposts' => -1,
        'post_type' => $field_keyn,
        'cat' => $fcat_list,
        'post_status' => 'publish',
        'relation' => 'OR',
    );
    // The Query
    // print_r($args ); 

    $my_query = new WP_Query($args);
    if ($my_query->have_posts()) {
        while ($my_query->have_posts()) :
            $my_query->the_post(); ?>

I think your argument array should be

$args = array ( 'numberposts' => -1,
                'post_type' => $field_keyn,
                'cat' => $fcat_list,
                'post_status' => 'publish',
                'orderby' => 'meta_value_num', 
                'meta_key' => 'metakeyname' );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM