【问题标题】:Wordpress: How to fetch record from wp_posts and wp_postmeta in desc order by meta_value?Wordpress:如何按 meta_value 的 desc 顺序从 wp_posts 和 wp_postmeta 中获取记录?
【发布时间】:2015-01-27 19:09:35
【问题描述】:

我想从 wp_posts 获取包含多个自定义帖子的记录,并按来自wp_postmeta.meta_value. 的多个元值按降序显示

现在,我正在使用这个查询:

    $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(); ?>

【问题讨论】:

    标签: php mysql wordpress inner-join


    【解决方案1】:

    我认为你的参数数组应该是

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

    【讨论】:

    • 您好,感谢您的回复。但我需要两个 meta_key meta_key = start_date, meta_key = news_date
    猜你喜欢
    • 1970-01-01
    • 2016-01-06
    • 2017-08-07
    • 1970-01-01
    • 2023-04-08
    • 2019-12-06
    • 1970-01-01
    • 2020-04-21
    • 1970-01-01
    相关资源
    最近更新 更多