Title: Current Category
Last modified: August 22, 2016

---

# Current Category

 *  Resolved [luisalonsobr](https://wordpress.org/support/users/luisalonsobr/)
 * (@luisalonsobr)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/current-category-1/)
 * Hi, thank you for this great plugin, one question:
 * I created a global variable that contains the current category, i would like 
   to change the code of my wpp plugin to get this variable when none is set on 
   the widget, but i can’t find where to replace this.
 * Can anyone shed light on this one?
 * [https://wordpress.org/plugins/wordpress-popular-posts/](https://wordpress.org/plugins/wordpress-popular-posts/)

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/current-category-1/#post-5449491)
 * Hi there,
 * I haven’t tested this modification, but I believe it should work:
    1. Go to _Plugins > Editor_ and pick _WordPress Popular Posts_ from the dropdown
       at the right.
    2. Find:
    3.     ```
           // * categories
           if ( !empty($instance['cat']) && $join_cats ) {
           	// ... rest of the code here
           ```
       
    4. … and replace it with:
    5.     ```
           if ( empty($instance['cat']) ) {
           	global $your_global_category_variable_here;
       
           	if ( is_numeric($your_global_category_variable_here) )
           		$instance['cat'] = $your_global_category_variable_here;
           }
       
           // * categories
           if ( !empty($instance['cat']) && $join_cats ) {
           	// ... rest of the code here
           ```
       
    6. Hit the _Update file_ button to save changes.
 * Note that any modifications made to plugin’s code will be lost the next time 
   WPP gets an upgrade.
 *  Thread Starter [luisalonsobr](https://wordpress.org/support/users/luisalonsobr/)
 * (@luisalonsobr)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/current-category-1/#post-5449676)
 * Thank You, will test and let you know!
 *  Thread Starter [luisalonsobr](https://wordpress.org/support/users/luisalonsobr/)
 * (@luisalonsobr)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/current-category-1/#post-5449703)
 * Worked like a charm. Thank you for your time and your plugin!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Current Category’ is closed to new replies.

 * ![](https://ps.w.org/wordpress-popular-posts/assets/icon-256x256.png?rev=1232659)
 * [WP Popular Posts](https://wordpress.org/plugins/wordpress-popular-posts/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wordpress-popular-posts/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wordpress-popular-posts/)
 * [Active Topics](https://wordpress.org/support/plugin/wordpress-popular-posts/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wordpress-popular-posts/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wordpress-popular-posts/reviews/)

## Tags

 * [category](https://wordpress.org/support/topic-tag/category/)
 * [current category](https://wordpress.org/support/topic-tag/current-category/)

 * 3 replies
 * 2 participants
 * Last reply from: [luisalonsobr](https://wordpress.org/support/users/luisalonsobr/)
 * Last activity: [11 years, 8 months ago](https://wordpress.org/support/topic/current-category-1/#post-5449703)
 * Status: resolved