WP查询

编程入门 行业动态 更新时间:2024-10-25 08:19:12
WP查询 - 无法按类别slug查询(WP Query - Unable to query by category slug)

我的自定义帖子中有四个类别“项目”类型是“现场”,“治疗”,“工作”和“播放”。 我有几个“项目”帖子没有我希望从档案页面中省略的类别。 在我的档案中,我的查询如下:

<?php $args = array( 'post_type' => 'projects','post_status' => 'publish', 'posts_per_page' => $projects_number, 'paged'=> $paged, 'category_name' => 'work,play,live,heal'); ?> <?php $wp_query = null; ?> <?php $wp_query = new WP_Query( $args ); ?> <?php if ( $wp_query->have_posts() ) : ?>

但我的档案并没有退回任何项目。 我也尝试了带有id的'cat'参数,但也没有用。 我错过了什么?

I have four categories in my Custom Post Type of "projects" that are 'live', 'heal', 'work', and 'play'. I have a few 'projects' posts with no category that I would like to omit from the archive page. In my archive, my query is as follows:

<?php $args = array( 'post_type' => 'projects','post_status' => 'publish', 'posts_per_page' => $projects_number, 'paged'=> $paged, 'category_name' => 'work,play,live,heal'); ?> <?php $wp_query = null; ?> <?php $wp_query = new WP_Query( $args ); ?> <?php if ( $wp_query->have_posts() ) : ?>

But my archive is not returning any projects. I also tried the 'cat' parameter with id's but no avail there either. What am I missing?

最满意答案

对于任何遇到这种情况的人来说......'category'参数需要在它自己的数组中

For anyone who comes across this...the 'category' argument needed to be in its own array

更多推荐

本文发布于:2023-07-31 00:14:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1340316.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:WP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!