WordPress.org

Forums

WordPress Popular Posts
[Plugin: WordPress Popular Posts] Exclude and include categories (7 posts)

  1. Gabor Almer
    Member
    Posted 3 years ago #

    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/

  2. Héctor Cabrera
    Member
    Plugin Author

    Posted 3 years ago #

    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!

  3. Gabor Almer
    Member
    Posted 3 years ago #

    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. Please use the pastebin]

    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.

  4. Héctor Cabrera
    Member
    Plugin Author

    Posted 3 years ago #

    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 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.

  5. Gabor Almer
    Member
    Posted 3 years ago #

    Hi,

    So in the end I will learn the rules of this forum :)
    Here it is: http://pastebin.com/v51QPSQw

    I also included the exclude category select modification.

    I had to modify the plugin with this fix, it's not in there, but I hope you will include it in the next release too.

    Thank you.

  6. DrLightman
    Member
    Posted 3 years ago #

    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!

  7. Héctor Cabrera
    Member
    Plugin Author

    Posted 3 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WordPress Popular Posts
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic