繁体   English   中英

显示特定类别的帖子-Wordpress数组

[英]Show posts from specific category - Wordpress array

我的模板选项上有这个数组:

$args = array(

                'post_type' => 'post',
                'posts_per_page' => 3,
                'ignore_sticky_posts' => 1,
                'tax_query' => array(
                    array(
                'taxonomy' => 'post_format',
                        'field' => 'slug',
                        'terms' => array('post-format-quote', 'post-format-link', 'post-format-audio'),
                        'operator' => 'NOT IN',
                        'category_name' => 'noticias'

                    )
                ),
                'meta_query' => array(
                    'relation' => 'OR',
                    array(
                        'key' => '_thumbnail_id',
                        'compare' => 'EXISTS'
                    ),
                    array(
                        'key' => 'MEDICAL_META_embed_code',
                        'compare' => 'EXISTS'
                    ),
                    array(
                        'key' => 'MEDICAL_META_gallery',
                        'compare' => 'EXISTS'
                    )
                )
            );

如果您看到'category_name' => 'noticias' ,noticias是我要在主页上显示的类别,但是该行不起作用,也许'category_name'不是这里的最佳选择...

我读过wordpress文档,但是没有数组示例,只有函数,有没有办法在这样的数组上完成此操作?

提前致谢!

对于特定类别的显示帖子,您可以使用WP Query功能,有关此功能,请参见链接

为了使阅读此线程的人受益,您可以使用以下参数过滤查询args数组中的特定类别

cat (int) - use category id.
category_name (string) - use category slug (NOT name).
category__and (array) - use category id.
category__in (array) - use category id.
category__not_in (array) - use category id.

只需修改数组即可解决OP的问题,如下所示

$args = array(
            'post_type' => 'post',
            'posts_per_page' => 3,
            'ignore_sticky_posts' => 1,
            'cat' => '777' // Put the cat ID here
            'tax_query' => array(
                array(
            'taxonomy' => 'post_format',
                    'field' => 'slug',
                     ... 
                     ...
                     )
             );

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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