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
- Insert array data on plugin activation
- Will simple function names in a class structure conflict with other plugins?
- Do my defines need to be unique?
- Custom category code not showing all posts
- WordPress php filter admin_body_class not working
- Instantiate class to be available to all plugin functions
- Category Thumbnail Display – How to display ONLY the main Category
- Common abstract class for plugins
- Where do posts get the sidebar from?
- How to test nonce with AJAX – Plugin development
- What does $wpdb->get_row return?
- WP add_action factory
- wp_loaded hook block script enquequing
- hover image appears below placeholder instead of overlayed
- combine Code 1 with Code 2
- WP nonce invalid
- get current product name in functions.php
- woocommerce subscriptions – get expiration date [closed]
- Same log message keeps on printing to debug.log file thousand of times
- get post based on category chosen in drop down – The ajax method
- How to use transient in this code for related post?
- Adding Default Settings to Theme My Login plugin
- Custom filter in admin edit custom post type responding with invalid post type?
- WordPress Scheduled Event Request Blocking
- How can i upload images in an admin page?
- Append HTML Using Shortcode
- Delete a WordPress transient from a shortcode on Page/Post update
- Creating a related post section based on similar categories
- Plugin CSS not enqueing
- Create onClick Event to Re-load a Widget
- Accessing the database from a plugin outside of action hooks
- Adding subdomain to home_url for “add_menu_page”
- How to show phpinfo() only in a new tab?
- How to find error in my code when the error message is pointing to WP core file?
- How to select the contents in the text view textrea in wp_editor?
- Proper syntax or method for keeping url in modified isotope / category links
- How to access global variable $menu inside a class function
- Filter Select results based on selection
- Hide categories that are not used in the post type
- What is an equivalent of single_cat_title for getting the slug of the category?
- Automated Cart Update With Alert Box Each Time
- How can I remove a function that has been added to wordpress with add_filter?
- PHP Fatal error: Uncaught mysqli_sql_exception: Table doesn’t exist in wordpress/wp-includes/wp-db.php
- Issue adding sub category programmatically
- WooCommerce/WordPress: how hide entire table form after submit (Admin Dashboard)?
- How to sanitize any integer input field in wordpress?
- How to set up VS Code for WP plugin/theme development in 2021? [closed]
- WordPress ajax doesn’t display object method on jQuery .change() function
- 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
- how do I get a specific post from a post with a subcategory in WP
- Singelton class does not work, multiple initialization on page reload
- Saving an array of dynamic repeater data as post_meta
- what is the best practice to add new field to an api route
- filter default query to show just selected level of child pages in wordpress
- WP grandchild categories in nested ul li
- Retrieve $_POST data submitted from external URL in WordPress(NOT API)
- WordPress wpform plugin submit and get multiple checked value from checkbox [closed]
- Grab posts by multiple categories
- How to upload a file to a folder named after the user_id via plugin
- Pass Category Name, Description and Photo into variables to pass to jQuery
- Reprinting tags with all attributes
- 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
- Move category description below post list in blog
- Use custom post type for a store locator
- developing a wordpress plugin, have a few PHP Woocommerce related coding questions
- How to pick the default selected value in wordpress dropdown?
- Improve page speed loading using CDN and async or defer attribute
- Applying A Category to Existing Posts Where Page Title Matches Regex
- Get page that displays all children of taxonomy parent
- How do I programmatically set a user as spam in BuddyPress? [closed]
- How to use $_GET function WordPress backend
- Whitelisting items from custom options page
- Add_menu_page not displaying the menu in class based plugin
- How to call plugin function per site in a multisite?
- Update results, Before deleting the related category [closed]
- How to make my custom widget appear within WordPress widgets? Plugin development
- Script to browser problem PHP
- adjust section according to country?
- How to auto fetch customer details in Woocommerce in checkout page
- Can’t upload image using media_sideload_image
- Store a default value for a transient on plugin activation
- selected option if current category is the value
- Adding widgets to my plugin page instead of WordPress dashboard
- WP CRON duplicate wp_insert_post with has < and > tag
- How wp-cron can run in background if PHP is single threaded?
- How to insert data into database using wp cron job
- How to send Ajax request from my plugin in admin dashboard?
- I want to add custom add to cart link [closed]
- Options API get_option() and update_option() Not Correctly Updating or Returning
- get_template_part based upon post’s category
- Execute long and heavy processes
- how to save selected option in variable for rest api category filter
- wp_head function not outputting
- wp query foreach deleting record returning only first or last item
- Extend PHP regex to cover “srcset” and “style” attributes