特定のカテゴリから「カスタムポストタイプ」を取得するためにWP_Queryにカテゴリ名/IDを含める方法は?

wordpress.stackexchange https://wordpress.stackexchange.com/questions/6975

質問

これが私が今使用しているコードです。 「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帰属
所属していません wordpress.stackexchange
scroll top