Support » Plugin: WordPress Popular Posts » Exclude Category not working

  • Resolved billcommexis

    (@billcommexis)


    I’ve been using this plugin for a while now and it has been working great. Recently a client had a request to have the ability to exclude certain posts from the list. I have edited the code to exclude a certain category, but posts with that category are still showing. If I change the code to only show posts with the new category, it works fine, but it will not exclude the category. Here is my code:

    <?php
                        $args = array(
                            'limit' => 5,
                            'range' => 'monthly',
                            'order_by' => 'views',
                            'post_type' => 'post',
                            'cat' => '-2933'
                        );
    
                        wpp_get_mostpopular( $args );
                        ?>

    Any help with this would be appreciated.

Viewing 15 replies - 1 through 15 (of 19 total)
  • Plugin Author Héctor Cabrera

    (@hcabrera)

    Hi there!

    Question: are posts associated to two or more categories by any chance?

    Yes, the post I was trying to exclude does have multiple categories. That was one of my original thoughts as to why it wasn’t being excluded from the list. I tested removing all categories other than the one I want to exclude and it still didn’t work.

    • This reply was modified 8 months, 2 weeks ago by  billcommexis. Reason: Reworded my response to be less confusing
    Plugin Author Héctor Cabrera

    (@hcabrera)

    That’s odd. It’s been a while since I last use the category exclusion feature so it probably is something simple to fix. I’ll run some tests and get back to you later.

    I appreciate the help. Please keep me updated.

    Any updates on this? I have a client that is still asking about this feature.

    Plugin Author Héctor Cabrera

    (@hcabrera)

    Hi there!

    Sorry for the late reply. Last week was a hectic one.

    Alright, for the test I added the stats_category parameter to $args to see the post category on the frontend and also removed the cat parameter, then ran the following code on localhost:

    <?php
    if ( function_exists('wpp_get_mostpopular') ) {
    
        $args = array(
            'limit' => 10,
            'range' => 'monthly',
            'order_by' => 'views',
            'post_type' => 'post',
            'stats_category' => 1
        );
        wpp_get_mostpopular( $args );
    
    }
    ?>

    Outputs:

    WPP list without category filtering

    Now, excluding the Random category using the cat parameter:

    <?php
    if ( function_exists('wpp_get_mostpopular') ) {
    
        $args = array(
            'limit' => 10,
            'range' => 'monthly',
            'order_by' => 'views',
            'post_type' => 'post',
            'stats_category' => 1,
            'cat' => '-1'
        );
        wpp_get_mostpopular( $args );
    
    }
    ?>

    Outputs:

    WPP list with category filtering

    As you can see, posts associated to the Random category were filtered out. So:

    • Are you running the latest version of the plugin?
    • Is there a caching plugin installed on your site right now?

    That new code seems to have worked. I appreciate all of the help!

    Plugin Author Héctor Cabrera

    (@hcabrera)

    Well, I really didn’t do anything. It’s basically your code with a couple of tweaks 😛

    Glad to know it’s working anyways 🙂

    noonecares

    (@thedeanamsterdam)

    Hey man great plugin but i have the same problem as mentioned above, but i cant find where to put the code?…

    I have a plugin that lets me categorize pages but i can’t include or exclude categories in your plugin now, i hope the code is the solution.
    Thank you!

    Plugin Author Héctor Cabrera

    (@hcabrera)

    Hi @thedeanamsterdam!

    Since it’s not the “stock” behavior in WordPress (pages are not supposed to use / have categories, that’s for posts and custom post types), WPP ignores the category filter when the post type is page.

    Here’s a “cheat” that will surely work with the current version of the plugin: set the Post type(s) field to page, nonexistent_post_type where nonexistent_post_type is a post type that, well, doesn’t really exist 😛

    P.S.: Be careful though, if I decide to add some sort of check for this in a future release of WPP this “cheat” will no longer be effective so I wouldn’t use this on a client’s project.

    P.S.S.: I didn’t test it, so you’ll have to let me / us know if it worked or not.

    noonecares

    (@thedeanamsterdam)

    nope when i add a category and save the widget, i come back and the category name is gone and not saved.

    noonecares

    (@thedeanamsterdam)

    so i opened the widget and put page, nonexistent_post_type in the Post type(s) field. And than i want to include only one category, but the category dissapears after i save the widget

    Plugin Author Héctor Cabrera

    (@hcabrera)

    If that didn’t work then you’re probably out of luck. I’ll give it another shot tomorrow and if there’s anything else worth trying I’ll let you know.

    noonecares

    (@thedeanamsterdam)

    okay please try one more time for me when you can, my site needs exactly what your plugin can do. Have a nice day!

    noonecares

    (@thedeanamsterdam)

    btw the plugin works fine when i only add post,page but i really need the category’s

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘Exclude Category not working’ is closed to new replies.