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 trial

WordPress

Scott Reuber
PLUS
Scott Reuber
Courses Plus Student 12,756 Points

Determining Cat ID for Excluding 'Featured' from Recent Posts

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.

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.

3 Answers

HI Scott,

I can't find the video that your talking about, but my guess is the category Zac has created has an ID of 1, but yours has an ID of 4. You are correct saying that it should be cat="-4" to exclude this category.

You can see from the WordPress Codex, "Exclude Posts Belonging to Category"

:)

Scott Reuber
Scott Reuber
Courses Plus Student 12,756 Points

Back from Thanksgiving vacation, so time to update this.

The video I'm referring to is this one: http://teamtreehouse.com/library/how-to-build-a-wordpress-theme/extending-wordpress-template-functionality/adding-content-in-custom-places-part-2

Around the 6:30 mark is where he is creating this category omission. It's his category ID that is 4 when he views it in admin, not mine, but just moments later in that same video, the value for cat he enters in the array is -1. I was assuming it should have been -4 in the video.

This is confusing, not sure if it's an error in the video or what.

Scott Reuber
PLUS
Scott Reuber
Courses Plus Student 12,756 Points

Still awaiting a response, preferably from Zac, on this one. This is still confusing.