WordPress Wednesdays: All Posts in a Parent Category

The need to show all posts in a particular category or that category’s sub categories is very high. There are not too many projects out there that do not require a customized search, a menu, or a listing of some sort where the user wants to include all posts (or exclude) that belong to a parent category. Until recently – there was no real good way to do this. You either had to hard code category names or IDs in an array, or get really creative.

I recently started using the following function mentioned in the WordPress Codex that made this very easy: post_is_in_descendant_category().

By using that function – you can test to see if a post is in a particular category or even several subcategories deep of that category and then use that to easily show exactly what you want.

Examples and documentation for post_is_in_descendant_category: http://codex.wordpress.org/Template_Tags/in_category

About the Author...

Jennifer Zelazny

My name is Jennifer Zelazny and this site is a collection of my random thoughts and opinions. I am Penn Stater, WordPress developer, and a modern day explorer. I love exploring data, trends, and things that make the world a better place and sharing them here.

Leave a Reply

Your email address will not be published.
You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
*
*

This site uses Akismet to reduce spam. Learn how your comment data is processed.