Getting the ID of a category page
-
Hello all,
I’ve been searching, unsuccessfully, for some sort of function that can be called in a category page and that returns the numeric ID corresponding to that category. After a great deal of brain-wracking, I finally resorted to modifying wp-includes/functions.php by adding the following function, which I based on is_category:
function fetch_category_id() {
global $wp_query;if ( !$wp_query->is_category )
return false;$cat_obj = $wp_query->get_queried_object();
return $cat_obj->cat_ID;
}This does just what I need, but it seems so simple in retrospect that it’s hard to believe WP doesn’t already have something like it. Have I reinvented the wheel?
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Getting the ID of a category page’ is closed to new replies.