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 trialScott Reuber
Courses Plus Student 12,756 PointsDetermining Cat ID for Excluding 'Featured' from Recent Posts
I asked this question in another thread and it seems to have fallen by the wayside, got missed, or 'something'. Would like an answer on this or have it clarified.
Following along the Wordpress Theme lessons for a project I'm working on, and during the video where Zac is putting together the front-page.php file, for the Recent Post section it's stated that we want to exclude posts with a category of Featured. To do this, we go into the admin, go to Categories, click 'Featured', and then up in the address bar we see tag_ID=4.
From there, back in front-page.php, we add an argument to our $args array with a key of 'cat' and a value of -1.
Around the 6:30 mark is where he is creating this category omission.
This is confusing. Where does -1 come from? Wouldn't it be 4 (or rather, -4, to exclude it), as the tag_ID suggests? Feel like I'm missing something.
2 Answers
Christopher Hall
9,052 PointsI'm not sure where this -1 came from either. It should be -4 according to the WP_Query reference page:
Exclude Posts Belonging to Category
Display all posts except those from a category by prefixing its id with a '-' (minus) sign.
$query = new WP_Query( 'cat=-12,-34,-56' );
Scott Reuber
Courses Plus Student 12,756 PointsI figured as much, just wanted to be sure I wasn't the only one who noticed this.