订购自定义wordpress循环

时间:2018-11-15 07:06:41

标签: wordpress loops

我有一个WordPress自定义循环,如下所示:

$args = array(  
    'post_type' => 'post',
    'post_status' => 'publish',
    'posts_per_page' => 6,
    'meta_key' => 'publication_type',
    'meta_value' => 'uma',
);

这显示6个发布类型为"uma"的帖子。 publication_type是使用“高级自定义字段”创建的字段。

我还创建了publication_year字段,其中包含2019, 2018, 2017,...

如何排序我所有的帖子降序?

以下示例无济于事:

$args = array(  
    'post_type' => 'post',
    'post_status' => 'publish',
    'posts_per_page' => 6,
    'order_by' => 'publication_year',
    'order' => 'DESC'
    'meta_key' => 'publication_type',
    'meta_value' => 'uma',
);

1 个答案:

答案 0 :(得分:1)

  $args = new WP_Query( array(
    'post_type' => 'post',
    'post_status' => 'publish',
    'posts_per_page' => -1,    
    'meta_query' => array(                                                   
                        array(
                            'key'     => 'publication_type',
                            'value'   => 'uma',
                        ),
                    ),
    'meta_key' => 'publication_year',
    'orderby'   => 'meta_value_num',
    'order' => 'ASC',
 ));