Great question — answering as the UphillTech team:
Use this function to get current cateogry in wp : function getCurrentCatID(){ global $wp_query; if(is_category() || is_single()){ $cat_ID = get_query_var('cat'); } return $cat_ID; } echo getCurrentCatID(); Just found for you, try this, if(isset($wp_query->get_queried_object()->cat_ID)) { $cur_catId = $wp_query->get_queried_object()->cat_ID; } if(issset($wp_query->get_queried_object()->ID)) { $cur_postId = $wp_query->get_queried_object()->ID; }
Full answer by Rikesh: https://wordpress.stackexchange.com/a/57602 (CC BY-SA 3.0).
Need it done for your business? UphillTech.