Last active
December 8, 2016 07:08
-
-
Save ryanve/de28f1b9f70c49de2a19 to your computer and use it in GitHub Desktop.
wordpress check if in category or parent category
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $in_category = function($cats) { | |
| if (in_category($cats)) return true; | |
| foreach ((array) $cats as $cat) { | |
| $subs = get_term_children((int) $cat, 'category'); | |
| if ($subs && in_category($subs)) return true; | |
| } | |
| return false; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
based on Testing_if_a_post_is_in_a_descendant_category