这是我现在正在使用的代码。它从“ sp_events”帖子类型中的所有类别中获取了帖子。

<?php $feat_art = new WP_Query(array('post_type' => 'sp_events','post_status' => 'publish','posts_per_page' => 1));   while($feat_art->have_posts()) : $feat_art->the_post(); ?>

我想仅显示名为“ EventCat1”的类别的帖子。我尝试了以下代码,但它不起作用。

<?php $feat_art = new WP_Query(array('post_type' => 'sp_events','category_name'=> 'eventcat1','post_status' => 'publish','posts_per_page' => 1));   while($feat_art->have_posts()) : $feat_art->the_post(); ?>

如何指定类别名称或查询中的ID?任何帮助,将不胜感激。谢谢

有帮助吗?

解决方案

以下代码有效。

<?php $feat_art = new WP_Query(array('post_type' => 'sp_events','sp_events_cat'=> 'eventcat1','post_status' => 'publish','posts_per_page' => 1));   while($feat_art->have_posts()) : $feat_art->the_post(); ?>
许可以下: CC-BY-SA归因
scroll top