Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialBecca MacPhee
116 Pointscustom post categories
I have added custom posts 'Webcasts' to my site, displaying only the first one on the homepage, code below:
<?php $num_posts = ( is_front_page() ) ? 1 : -1;
$args = array(
'post_type' => 'webcasts',
'posts_per_page' => $num_posts
);
$query = new WP_Query( $args );
?>
I have created 3 categories for this post type (next webcast, previous webcast, and upcoming webcasts). On this page, I only want to display one of these categories, how do I do this??
5 Answers
Becca MacPhee
116 PointsIn case this helps anyone else I have figured out the problem, correct code is:
$args = array( 'post_type' => 'meetings', 'category_name' => 'next-meeting', );
So happy right now!!! :-)
Chris McKirgan
5,666 PointsThis may be of some use to you: https://css-tricks.com/snippets/wordpress/run-loop-on-posts-of-specific-category/
$args = 'cat=5'; // ID of the category
$query = new WP_Query( $args );
Becca MacPhee
116 Pointsok, I've changed it to this but now it won't display any posts... ?
$num_posts = ( is_front_page() ) ? 1 : -1;
$args = array(
'post_type' => 'webcasts',
'posts_per_page' => $num_posts
);
$args = 'cat=next-webcast';
$query = new WP_Query( $args );
Becca MacPhee
116 PointsI've also tried this which seems like it should work, but it just displays the first post, not the specific category :/
$args = array( 'post_type' => 'webcasts', 'cat' => 'next-webcast', 'posts_per_page' => $num_posts );
Becca MacPhee
116 PointsI'm still stuck on this, please can anyone help???