WordPress Popular Posts
[resolved] [Plugin: WordPress Popular Posts] Need to limit category for non-widget use (6 posts)

  1. cerulean
    Posted 6 years ago #

    I'm using WPP within a series of sidebar tabs and need to limit what pages appear. For one, Home appears as a top result. There are also a couple of categories I'd like to exclude. Below is what I have so far. Please let me know what I can add to allow for removal of certain category / page IDs. Thanks!

    <?php if (function_exists('wpp_get_mostpopular')) wpp_get_mostpopular('stats_comments=0 & range=all & order_by=all & limit=8'); ?>


  2. Héctor Cabrera
    Posted 6 years ago #

    Hi cerulean,

    You need to use the cats_to_exclude parameter to specify which categories you wish to have excluded, like this:

    if (function_exists('wpp_get_mostpopular')) wpp_get_mostpopular('stats_comments=0&range=all&order_by=comments&limit=8&cats_to_exclude=1,5,33');

    For a more complete list of available paramaters and its usage please go to your wp-admin > Settings > WordPress Popular Posts page.

    P.S.: the order_by parameter only accepts the following values: comments, views, avg. Make sure you use the right ones or my plugin will automatically switch to the default values.

  3. cerulean
    Posted 6 years ago #

    This is great info, thanks for the timely response. The only thing that's still showing up as popular is Home which is a page (and not a post with an assigned category). How can I exclude this specific page from the results?

  4. Héctor Cabrera
    Posted 6 years ago #

    Unfortunately, there's no way to achieve this with the current version of my plugin. You'll have to hack through the code of my plugin to do this.

    Open wordpress-popular-posts.php using an editor such as Windows' Notepad or Adobe Dreamweaver, and change this code (around line 608):

    $mostpopular = $wpdb->get_results("SELECT $wpdb->posts.ID, $wpdb->posts.post_title $fields FROM $wpdb->posts $join WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_password = '' AND $range $force_pv $nopages $exclude GROUP BY $wpdb->posts.ID ORDER BY $sortby DESC LIMIT " . $instance['limit'] . "");

    ... into this:

    $mostpopular = $wpdb->get_results("SELECT $wpdb->posts.ID, $wpdb->posts.post_title $fields FROM $wpdb->posts $join WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_password = '' AND $range $force_pv $nopages $exclude AND $wpdb->posts.ID NOT IN(15) GROUP BY $wpdb->posts.ID ORDER BY $sortby DESC LIMIT " . $instance['limit'] . "");

    ... where AND $wpdb->posts.ID NOT IN(15) specifies the ID of the page(s) you want to exclude (in your case, it should be the ID of the home page).

  5. cerulean
    Posted 6 years ago #

    That worked beautifully, except for hacking up your great plugin : )

    Thanks for your help (and very clear explanations!)

  6. Héctor Cabrera
    Posted 6 years ago #

    You're welcome! I might include a page/post excluding feature on a future release of my plugin to make this more simple and keep people from having to hack my plugin :P

    Thank you for your words!

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