Created
April 8, 2011 15:33
-
-
Save danott/910115 to your computer and use it in GitHub Desktop.
WordPress function to accurately retrieve the current category ID outside the loop.
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 | |
| /* current_category_ID() | |
| * | |
| * Get the currently-being-viewed category's ID. | |
| * | |
| * THE PROBLEM: | |
| * WordPress offers no easy way to get the id of the category that is currently | |
| * being viewd in an index.php. It offers nice conventions to get the title and | |
| * description (within the loop), but I needed this information outside the loop. | |
| * | |
| * THE SOLUTION: | |
| * After searching WordPress' documentation, get_queried_object() finally emerged | |
| * as a way to functionally get this information. | |
| */ | |
| function current_category_ID() | |
| { | |
| $category = get_queried_object(); | |
| return $category->term_id; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment