• Resolved Grzegorz.Janoszka

    (@grzegorzjanoszka)


    I have limited revisions in my wp-config:
    define(‘WP_POST_REVISIONS’, 3);

    The problem is, top10 keeps showing me revisions. When for example my most popular post for a day has 1000 views so far, I edit it, a revision is created and then I have two identical posts on top of the list, one with a type ‘post’ and 1030 views (growing) and the other one with a type ‘revision’ and frozen 1000 views.

    Is there any way that top 10 doesn’t show revisions in posts list?

    Thank you for such a fantastic plugin!

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Ajay

    (@ajay)

    That is a bug. There needs to be an additional setting in the WHERE clause which I think might work. Are you in a position to test this?

    https://github.com/WebberZone/top-10/blob/99e225f34dab528bf76c1e0be9b30b91a003d92d/includes/public/display-posts.php#L386

    New line:

    
    $where .= " AND $wpdb->posts.post_type <> 'revision' ";
    
    Thread Starter Grzegorz.Janoszka

    (@grzegorzjanoszka)

    I added it to /wp-content/plugins/top-10/includes/public/display-posts.php after line 386, so together it shows:

    $where .= ” AND $wpdb->posts.post_type IN (‘” . join( “‘, ‘”, $post_types ) . “‘) “; // Array of post types
    $where .= ” AND $wpdb->posts.post_type <> ‘revision’ “;

    but it doesn’t work. And it shouldn’t as post_types I marked are only posts and pages, nothing else. Thus the excluding of revisions will not work here, I think.

    Thread Starter Grzegorz.Janoszka

    (@grzegorzjanoszka)

    BtW, there might be another bug too.
    In top-10 options I have marked:

    Post types to include in results (including custom post types):
    X post
    X page
    attachment

    And the SQL queries are:

    SELECT DISTINCT ID, postnumber, cntaccess as sum_count
    FROM wp_top_ten
    INNER JOIN wp_posts
    ON postnumber=ID
    WHERE 1=1
    AND blog_id = 1
    AND (wp_posts.post_status = ‘publish’
    OR wp_posts.post_status = ‘inherit’)
    AND wp_posts.post_type IN (‘post’, ‘page’, ‘attachment’)
    AND wp_posts.post_type <> ‘revision’
    ORDER BY sum_count DESC
    LIMIT 0, 10

    SELECT DISTINCT ID, postnumber, SUM(cntaccess) as sum_count
    FROM wp_top_ten_daily
    INNER JOIN wp_posts
    ON postnumber=ID
    WHERE 1=1
    AND blog_id = 1
    AND (wp_posts.post_status = ‘publish’
    OR wp_posts.post_status = ‘inherit’)
    AND dp_date >= ‘2017-03-18 0’
    AND wp_posts.post_type IN (‘post’, ‘page’, ‘attachment’)
    AND wp_posts.post_type <> ‘revision’
    GROUP BY postnumber
    ORDER BY sum_count DESC
    LIMIT 0, 10

    So first of all – revisions are shown – and secondly: attachment is still being asked for despite they are not selected.

    Please check it.

    [Update] – now I realized you may ask for attachments and filter them out later on in processing. Wouldn’t it be way better not to ask for attachments in the first place without filtering them later?

    Plugin Author Ajay

    (@ajay)

    Hi,

    Are you looking at the queries being generated by the widget by any chance? These usually override the queries of the main settings page.

    I don’t filter out attachments later, as far as I recall

    I’m still trying to figure out revisions as that doesn’t make sense to me as to why they show.

    I agree on the AND wp_posts.post_type <> ‘revision’ as it’s not going to help.

    In the queries above, do you see the revisions in the list of posts?

    Thread Starter Grzegorz.Janoszka

    (@grzegorzjanoszka)

    On a normal blog page I have just the widget with the most popular content overall. In admin interface I have two widgets – overall most popular and today most popular. The queries generated previously where by the admin interface.

    Just to provide more data: normal widgets don’t show revisions – they work well. The problem is when I click on “View all popular posts” – then I get a view WITH revisions. But when I click on “View all daily popular posts”, I don’t see any revisions. Sorry for being not precise previously.

    Now, these are queries generated by the non-admin widget, I am on a normal blog page, not admin interface (no revisions here):

    SELECT post_id, meta_value
    FROM wp_postmeta
    WHERE meta_key = ‘tptn_post_meta’

    SELECT DISTINCT ID, postnumber, cntaccess as sum_count
    FROM wp_top_ten
    INNER JOIN wp_posts
    ON postnumber=ID
    WHERE 1=1
    AND blog_id = 1
    AND (wp_posts.post_status = ‘publish’
    OR wp_posts.post_status = ‘inherit’)
    AND wp_posts.post_type IN (‘post’, ‘page’)
    AND wp_posts.post_type <> ‘revision’
    ORDER BY sum_count DESC
    LIMIT 0, 60

    (the line suggested by you is still in place)

    SELECT *
    FROM wp_posts
    WHERE ID = 39
    LIMIT 1

    SELECT *
    FROM wp_posts
    WHERE ID = 654
    LIMIT 1

    SELECT *
    FROM wp_posts
    WHERE ID = 1445
    LIMIT 1

    SELECT *
    FROM wp_posts
    WHERE ID = 3372
    LIMIT 1

    Plugin Author Ajay

    (@ajay)

    Thanks. This is helpful debugging. So it seems to be a query with my popular posts interface only in the admin area. I think I know why because I use a separately constructed query there which doesn’t have AND wp_posts.post_type IN (‘post’, ‘page’) if I recall correctly.

    Thread Starter Grzegorz.Janoszka

    (@grzegorzjanoszka)

    It is fixed now, thank you! ??

    Plugin Author Ajay

    (@ajay)

    Thanks for confirming. I just pushed through the version that fixed this.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Top 10 showing revisions’ is closed to new replies.