Title: [Plugin: WordPress Popular Posts] Exclude and include categories
Last modified: August 20, 2016

---

# [Plugin: WordPress Popular Posts] Exclude and include categories

 *  [Gabor Almer](https://wordpress.org/support/users/almergabor/)
 * (@almergabor)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/plugin-wordpress-popular-posts-exclude-and-include-categories/)
 * I wanted not to exclude but to include categories in the wordpress popular posts
   configuration.
    So I cloned the exclude category feature, and I realized that
   the select that is used has an unnecessary subselect. The original select is:
 *     ```
       $exclude = " AND $wpdb->posts.ID NOT IN (
   
       SELECT  object_id
       FROM    $wpdb->term_relationships AS r
               JOIN $wpdb->term_taxonomy AS x ON x.term_taxonomy_id = r.term_taxonomy_id
               JOIN $wpdb->terms AS t ON t.term_id = x.term_id
       WHERE   x.taxonomy = 'category'
               AND object_id IN
                  (
                   SELECT object_id
                   FROM $wpdb->term_relationships AS r
                   JOIN $wpdb->term_taxonomy AS x ON x.term_taxonomy_id = r.term_taxonomy_id
                   JOIN $wpdb->terms AS t ON t.term_id = x.term_id
                   WHERE   x.taxonomy = 'category'
                   AND t.term_id IN  (".$instance['exclude-cats']['cats']."))) ";
       ```
   
 * It can be substituted with the way more simple (and quicker):
 *     ```
       $exclude = " AND $wpdb->posts.ID NOT IN (
   
       SELECT  object_id
       FROM    $wpdb->term_relationships AS r
               JOIN $wpdb->term_taxonomy AS x ON x.term_taxonomy_id = r.term_taxonomy_id
               JOIN $wpdb->terms AS t ON t.term_id = x.term_id
       WHERE   x.taxonomy = 'category'
               AND t.term_id IN  (".$instance['exclude-cats']['cats'].")) ";
       ```
   
 * I tested it and it works smoothly.
 * How can I send the modified source to the plugin’s owner?
 * [http://wordpress.org/extend/plugins/wordpress-popular-posts/](http://wordpress.org/extend/plugins/wordpress-popular-posts/)

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

 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/plugin-wordpress-popular-posts-exclude-and-include-categories/#post-2415432)
 * Hi almergabor,
 * Usually, I check the forums every now and then so posting here is good enough
   most of times. Thanks for sharing this, will take a look into it and run some
   test on my own.
 * Again, thanks for contributing!
 *  Thread Starter [Gabor Almer](https://wordpress.org/support/users/almergabor/)
 * (@almergabor)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/plugin-wordpress-popular-posts-exclude-and-include-categories/#post-2415462)
 * Hi Héctor,
 * In the update function, after exclude-cats active and cats initialization:
 *     ```
       $instance['include-cats']['active'] = $new_instance['include-cats'];
       			$instance['include-cats']['cats'] = empty($new_instance['included']) ? '' : (ctype_digit(str_replace(",", "", $new_instance['included']))) ? $new_instance['included'] : '';
       ```
   
 * In the form function, after exclude-cats default values:
 *     ```
       'include-cats' => array(
       					'active' => false,
       					'cats' => ''
       				),
       ```
   
 * and after exclude category checkbox and combo:
    _[Code moderated as per the [Forum Rules](http://codex.wordpress.org/Forum_Welcome#Posting_Code).
   Please use the [pastebin](http://wordpress.pastebin.com/)]_
 * In the wpp_shortcode function after cats_to_exclude:
    `'cats_to_include' => '','`
 * And in shortcode_ops:
 *     ```
       'include-cats' => array(
       					'active' => empty($cats_to_include) ? false : (ctype_digit(str_replace(",", "", $cats_to_include))) ? true : false,
       					'cats' => empty($cats_to_include) ? '' : (ctype_digit(str_replace(",", "", $cats_to_include))) ? $cats_to_include : ''
       				),
       ```
   
 * And of course there sould be a ‘Categories to include’ string in the po file.
 * I’m new in this forum, but this is the easiest way to discuss some new features?
   🙂
    Sorry for being long.
 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/plugin-wordpress-popular-posts-exclude-and-include-categories/#post-2415473)
 * No problem, I actually like it when people take the time to write things ^^.
 * Usually, most people simply post ideas here and discuss it with me. If it’s a
   good one, chances are that it’ll be shipped with the next version of my plugin.
   When someone posts code, however, the forum rules ask us to use [pastebin](http://wordpress.pastebin.com/)
   to keep things clean ^^ (it’s alright, you didn’t know hehe).
 * You might want to consider posting the entire WPP code on pastebin and add a 
   few comments to see what was changed and where.
 *  Thread Starter [Gabor Almer](https://wordpress.org/support/users/almergabor/)
 * (@almergabor)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/plugin-wordpress-popular-posts-exclude-and-include-categories/#post-2415477)
 * Hi,
 * So in the end I will learn the rules of this forum 🙂
    Here it is: [http://pastebin.com/v51QPSQw](http://pastebin.com/v51QPSQw)
 * I also included the exclude category select modification.
 * I had to modify the plugin with this [fix](http://wordpress.org/support/topic/plugin-wordpress-popular-posts-fix-sorry-no-data-so-far-can-be-fixed-like-this),
   it’s not in there, but I hope you will include it in the next release too.
 * Thank you.
 *  [DrLightman](https://wordpress.org/support/users/drlightman/)
 * (@drlightman)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/plugin-wordpress-popular-posts-exclude-and-include-categories/#post-2415648)
 * Thank you both guys, I needed both the plugin and the include category support
   🙂
 * But, I noticed that at present time plugin version is 2.2.1 while the modified
   version with the include cat thing is 2.1.6, si I guess Héctor forgot to include
   this feature in the latest release? I hope he does, it’s useful!
 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/plugin-wordpress-popular-posts-exclude-and-include-categories/#post-2415654)
 * Hi DrLightman,
 * Yes, the category exclusion/inclusion feature has not been added yet. I’ll be
   getting some spare time within the next few days so I’m probably going to spend
   some hours playing with this.

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

The topic ‘[Plugin: WordPress Popular Posts] Exclude and include categories’ 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/)

 * 6 replies
 * 3 participants
 * Last reply from: [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * Last activity: [14 years, 4 months ago](https://wordpress.org/support/topic/plugin-wordpress-popular-posts-exclude-and-include-categories/#post-2415654)
 * Status: not resolved