• Resolved poco06

    (@poco06)


    Hello,

    Thanks for this helpful plugin. I’m wondering if it possible to restrict the count only for a specific postype in order not to overload the other part of the site (and also, the datatable postmeta).

    Let me know
    Regards
    Pat

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Lester Chan

    (@gamerz)

    If you use the latest version of the plugin https://github.com/lesterchan/wp-postviews/archive/master.zip,

    You can do the following in functions.php

    
    add_filter( 'postviews_should_count', 'postviews_should_count', 10, 2 );
    function postviews_should_count( $should_count, $id ) {
        $post = get_post ( $id );
        return $post->post_type === 'post';
    }
    
    Thread Starter poco06

    (@poco06)

    Hi and thanks for your quick answer.

    I have tried but your plugin continue to record all views in the database.
    I would like to record only the views that are related to a specific postype, just to ensure to limit database access.
    Any idea?
    Regards
    ¨Pat

    Plugin Author Lester Chan

    (@gamerz)

    Did you replace ‘post’ with the post_type?

    DO note that existing posts that already have the views will not be affected. Only newer created post will not increment their post, but they will still have a initial value of 0 in the views meta.

    • This reply was modified 7 years, 11 months ago by Lester Chan.
    Thread Starter poco06

    (@poco06)

    Hi,

    Yes I have replaced post with my specific postype I want to follow on views.
    I have also deleted all previews meta with ‘views’ key and as soon as I display a page, a new meta is created for this page.
    For info, I’m using the WP Fastest Cache cache plugin. Do you think this is something that could have an influence on this?
    Regards
    Pat

    Plugin Author Lester Chan

    (@gamerz)

    Does the new meta contains 0 or it keeps increasing? I am not sure on the caching part as this plugin was never designed to be used with caching.

    Thread Starter poco06

    (@poco06)

    Hi,

    Seems this is increasing each time we display a page (including the home page).
    I have no record with 0. All records have a number >0
    Regards
    Pat

    Plugin Author Lester Chan

    (@gamerz)

    The other way I can think of is to change
    https://github.com/lesterchan/wp-postviews/blob/master/wp-postviews.php#L56

    From
    if ( is_single() || is_page() ) {

    To
    if ( is_single() && ! is_page() ) {

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Restrict to only specific postypes’ is closed to new replies.