Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
定制wordpress循环_Wordpress_Loops - Fatal编程技术网

定制wordpress循环

定制wordpress循环,wordpress,loops,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\u typ

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

$args = array(  
    'post_type' => 'post',
    'post_status' => 'publish',
    'posts_per_page' => 6,
    'meta_key' => 'publication_type',
    'meta_value' => 'uma',
);
这显示了6篇发布类型等于
“uma”
的文章。
publication\u type
是使用高级自定义字段创建的字段

我还创建了一个字段
publication\u 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',
);

对不起,这个不行。这将提供比我编辑上述代码的出版物_type=“uma”@DennisPerremans下更多的帖子。请现在检查。确保您的meta_键名称正确。不,抱歉,它仍然显示带有publication_type=“member”和publication_type=“press”的帖子。@DennisPerremans R您确保存储了名为“publication_type”的自定义字段,因为此代码没有问题,对我来说它工作正常。我对它进行了测试。请重新验证您的字段名并在数据库中检查其值。因为这里没有使用“publication\u type”值,所以出现了问题。是的,我可以向您保证正确的字段名是“publication\u type”,这是一个选择。“出版年份”是一个数字字段。我通过打印这些自定义字段的值对其进行了双重检查。
  $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',
 ));