Ready to get started?Download WordPress


Excluding post from 'Popular Posts Bars' plugin (2 posts)

  1. gnruble
    Posted 1 year ago #

    I've been using the Engadget-style popular posts plugin - which works great, but I need to exclude a single post from being displayed.

    I know almost nothing about PHP and I'm not sure exactly how difficult (or easy?) it might be to accomplish this, but I was wondering if any of you guys could help me out?

    I'm pretty sure that the part I need to modify is the following;

    else {
          $most_viewed_posts = $wpdb->get_results("SELECT " . $wpdb->prefix . "posts.id, " . $wpdb->prefix . "posts.post_title, " . $wpdb->prefix . "posts.post_status, " . $wpdb->prefix . "posts.guid, COUNT(" . $mostviewedbars_table . ".post_id) AS view_count FROM " . $wpdb->prefix . "posts JOIN " . $mostviewedbars_table . " ON " . $mostviewedbars_table . ".post_id = " . $wpdb->prefix . "posts.id WHERE " . $wpdb->prefix . "posts.post_status = 'publish' AND " . $mostviewedbars_table . ".date > '" . $time_start . "' GROUP BY " . $mostviewedbars_table . ".post_id ORDER BY view_count DESC, post_date DESC LIMIT " . $instance['number_posts']);

    Can anyone think of a quick way to exclude a specific post by category here?

    And again; I'm not a Web developer, so I'm not even sure if this is the right snippet of code, but it seems like it would be.


  2. bcworkz
    Posted 1 year ago #

    You're right, modifying that get_results() query to exclude a particular category is the best place to do what you want. But excluding by category complicates the query because it is stored in a different table that requires a few joins to link the particular term to the post.

    OTOH, if you know the single post id number you need to exclude, it's fairly easy. The first and last lines exist, add the middle, substituting the actual number for my 222.

    WHERE " . $wpdb->prefix . "posts.post_status = 'publish'
    AND " . $wpdb->prefix . "posts.ID != 222
    AND " . $mostviewedbars_table . ".date > '" . $time_start . "'

    There might be some stupid syntax error, but that's the gist of it.

Topic Closed

This topic has been closed to new replies.

About this Topic