WordPress.org

Ready to get started?Download WordPress

Forums

WordPress Popular Posts
[resolved] Exlude Certain Posts? (7 posts)

  1. rhythmdoctor
    Member
    Posted 3 years ago #

    Is there any way to exclude certain posts? I have some really old posts that are extremely popular but I would rather not include them in this list. Is that possible? Thanks.

  2. rhythmdoctor
    Member
    Posted 3 years ago #

    ??

  3. H├ęctor Cabrera
    Member
    Plugin Author

    Posted 3 years ago #

    Hi there,

    Currently, there's no way to achieve this without hacking WordPress Popular Posts' code. If you feel like messing around with it, this is what you need to do:

    # Open wordpress-popular-posts.php using an editor such as Windows' Notepad or Adobe Dreamweaver, find this line:

    $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'] . "");

    ... and change it to:

    $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(1,3,17,8) GROUP BY $wpdb->posts.ID ORDER BY $sortby DESC LIMIT " . $instance['limit'] . "");

    Notice the AND $wpdb->posts.ID NOT IN(1,3,17,8) part? Replace the numbers with the actual IDs of the posts you wish to exclude (comma separated) from the list.

  4. rhythmdoctor
    Member
    Posted 3 years ago #

    Thank you SOO much. Alternatively, and perhaps a featured request, Id love to have this built in along with the ability to show popular posts with a limit as to how far back. IE = I could then do a popular posts this week that only draws from posts published during that week, etc.... Anyways, thank you very much for this. Ill try it out.

  5. rhythmdoctor
    Member
    Posted 3 years ago #

    lkki,

    Would you be so kind as to show me how to do the same thing (manually) but to force it to choose between posts published so many days old? IE, is there a way to add a filter that chooses popular posts, only if published within "X" days? Thanks again. The solution above worked and is very helpful so thanks for that

  6. simosmme
    Member
    Posted 3 years ago #

    i would like that option too please!

    to add a filter that chooses popular posts, only if published within "X" days?

    how can we do that?

    please help!

  7. lstelie
    Member
    Posted 3 years ago #

    @Ikki24

    Congrats, your hack to exclude a specific post works great.

    Luc

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic