Here is the code I'm using right now. It fetches the posts from all the categories in the 'sp_events' post type.
<?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(); ?>
I want to display the posts only from a category named 'eventcat1'. I tried the following code, but it did not work.
<?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(); ?>
How to specify either the category name or the id in the query? Any help would be appreciated. Thanks
category_name
is the correct way to do it. Silly thing to ask: you are sure there is at least one custom post that is attached to theeventcat1
category, and thateventcat1
is a regular category, not another custom taxonomy term? (If you reply, please use@Jan
so I get a notification)