WordPress.org

Ready to get started?Download WordPress

Forums

WordPress Popular Posts
[resolved] New Template Tag Not Removing Category (9 posts)

  1. Jonathan
    Member
    Posted 1 year ago #

    Due to the update we noticed problems with the old 'get_mostpopular()' template tag. Based on the documentation we changed to the 'wpp_get_mostpopular()' template tag. Everything seems to be working correctly except the ability to exclude certain categories. The code we are using is:

    <?php wpp_get_mostpopular("cat=-88&order_by=views&range=all&limit=5&stats_comments=0&post_type=post"); ?>

    Unfortunately, the posts in category 88 are still showing. Are we doing something incorrectly?

    http://wordpress.org/extend/plugins/wordpress-popular-posts/

  2. jitujazz123
    Member
    Posted 1 year ago #

    The same error at my. I restored the previous version and got it working again! But, the new version needs a bit more touch up!

  3. Héctor Cabrera
    Member
    Plugin Author

    Posted 1 year ago #

    Hi guys,

    Will look into this. Thanks for reporting.

  4. Jonathan
    Member
    Posted 1 year ago #

    It took me some time, but I tracked down the problem here. The issue is on line 1460 of wordpress-popular-posts.php. The function ctype_digit returns false if it finds any minus signs in the string, so trying to exclude any categories will just return an empty string. I replaced line 1460 from:

    'cat' => (ctype_digit(str_replace(",", "", $cat)) && !empty($cat)) ? $cat : '',

    to:

    'cat' => (preg_match('/^[0-9-]*$/', str_replace(",", "", $cat)) && !empty($cat)) ? $cat : '',

    and that seemed to fix the problem.

    Hector, if you'd like I can send over a diff file, but I figure the change is straightforward enough.

    jitujazz123, I hope that's helpful.

  5. Héctor Cabrera
    Member
    Plugin Author

    Posted 1 year ago #

    Good catch, Jonathan. Just updated the plugin and the fix should be available within the next 30 minutes. Simply redownload the plugin and let me know if you encounter any further issues.

  6. Jonathan
    Member
    Posted 1 year ago #

    Thanks for taking care of it so quickly Hector. I like the adjustment you made too, going with |[^0-9,-]| in a replace instead of checking if they exist. Much cleaner.

  7. Jonathan
    Member
    Posted 1 year ago #

    I went to update the plugin to the newest version and it says that we're already using the newest version. Did you add those changes without tagging a new version?

  8. Héctor Cabrera
    Member
    Plugin Author

    Posted 1 year ago #

    Yup, since it was just a single fix I didn't want to tag it as a new version.

  9. Jonathan
    Member
    Posted 1 year ago #

    Thanks for the update and for taking care of everything so quickly.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic