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;
}
Related Posts:
- Swapping wp_dropdown_categories function with wp_category_checklist
- PHP get_category() function redeclared
- Include WP_Query in my own PHP file?
- How to use update and delete query in wordpress
- add_meta_boxes action with refresh on save
- Allow authors to post only in categories they create in WordPress
- Resize Image without cropping
- Custom plugin issue when trying to use the shortcode twice on a page [closed]
- When is is_admin() available?
- Custom Loop through category menu to include sub categories
- Get posts with at least one category in common with current post?
- Hiding WordPress Plugin Source Code
- Woocommerce – remove product from category
- Get category name from custom loop and echo it once
- wp_loaded hook block script enquequing
- hover image appears below placeholder instead of overlayed
- get current product name in functions.php
- Custom filter in admin edit custom post type responding with invalid post type?
- How to find error in my code when the error message is pointing to WP core file?
- How to access global variable $menu inside a class function
- Filter Select results based on selection
- How to exclude category ID from Looper in WordPress
- Custom user login page by creating a plugin
- Add a specific part of current category page url to shortcode
- Singelton class does not work, multiple initialization on page reload
- How to upload a file to a folder named after the user_id via plugin
- How to fetch products with the price in a page on woocommerce using a form or live search with php
- How to show single category archive
- developing a wordpress plugin, have a few PHP Woocommerce related coding questions
- How to pick the default selected value in wordpress dropdown?
- Whitelisting items from custom options page
- Add_menu_page not displaying the menu in class based plugin
- adjust section according to country?
- Hide subcategories (widget)
- How to show only subcategories in parent category not parent category?
- What exactly do this function declared into functions.php file of a WP theme?
- How to use html inside a functions.php code?
- WordPress Environment: Dynamic Page using shortcode – how to change the page name for sharing
- Extend Woocommerce Widget Class – WC_Widget_Product_Categories
- plugin add action hook is not working :
- zip unzip attachments in wordpress
- Get latest post from all categories except one
- wordpress admin plugin menu custom css
- In WordPress, how do I get the number of posts next to single_cat_title(”); in the category.php file?
- Custom post type category not displaying category ID
- How to get current post category details inside “loop”?
- how to Update 15k products on plugin activation with meta_option
- Hooks for post saving make a post-new.php to load latest post’s data
- Adding Additional Variables on Menus Page
- Using flickr api in custom wordpress plugin
- Toolbar Hidden in a Virtual Page
- Get the list of post categories
- WordPress – Get Posts with Category data
- How to use wp_send_json() and output the value with ajax?
- Woocommerce. Get a list of products in the current category on the archive page and product page
- How to show categories and date on posts
- Problem with inserting multiple images in gallery of each WooCommerce product programmatically
- Is it possible to access admin-ajax.php using PHP?
- Call to “admin_notices” hook from a static method
- How to Create custom block for displaying information in content section which act like shortcode
- How to detect and handle the time difference between server and user in WordPress?
- How to setup the Email piping in WordPress plugin?
- Add a “custom field” to a category that can be retrieved when viewing the category page with get_post_meta
- Allow two posts (from different categories) to have the same slug
- Reliable way to add nonce to HTTP Header in WordPress?
- Getting an error when my plugin is updated, but the files update correctly
- Creating a POP Alert
- ssl redirect function is not working
- How to enable HTML tags in category description without breaking the category page
- WordPress Plugin Development – get_option error
- how to add new PHP page in WordPress plugin
- How can I get my WordPress plugin to receive data and relay it in an ajax/php request to a remote server that requires authentication?
- Trying to show the category of a post in the post display
- Constant expression contains invalid operations plugin class properties visibility
- Gutenberg blocks shortcodes compatibility
- Save custom field on WP_List_Table
- Load script and styles using an array of resources
- Input field duplicates on form submit by jQuery
- Customizing the output of the archive and category widget without altering the original behavior of the widget
- Code works on page-example.php by not category-example.php
- get_category display only 1
- Unable to pass variable to database
- Gravity Forms Marketo Plugin Feed [closed]
- Add custom filter to register data in array
- Make an array listing custom taxonomy
- Get category id for a custom category and display it in a class
- wp_get_archive for category returning different URLs on different but similar sites
- Trouble using wordpress functions in a pop-up modal form
- MySQL update text field with ‘
- how can I make content from a plugin hidden when user is logged in? [duplicate]
- display php code in header using wp_head()
- How to insert the first letter in uppercase [closed]
- Redirect users by role to custom pages
- Hide child of parent categories already hidden with “get_terms_args” – Woocommerce
- getJSON response to PHP
- Custom plugin with shortcode not working
- Get category name of current post (CPT UI)
- wp_register_script – illegal string offset
- Exclude a category ID from the following function
- How can I modify the html output of a custom post type admin page?