• Resolved grumo64

    (@grumo64)


    Hey, thank you for your plugin.

    Could you please tell me how to change the jp_post_views_cache_duration?

    best regards.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic 🚀

    You can use a code snippet that you would add to a functionality plugin on your site. In that code snippet, you would define a number of seconds for the cache duration (it is set to 3600 seconds, i.e. an hour, by default). In the example below, I’ve changed the duration to 2 hours:

    add_filter( 'jp_post_views_cache_duration', function () { return 7200; } );
    Thread Starter grumo64

    (@grumo64)

    Thank you Jeremy!
    I saw that many people asked you to show Post count view in admin column.
    I did it already and it works. The only thing I don’t know is the speed performance on the admin.

    I put my code here, let me know what you think about it:

    function kb_add_views_column( $cols ) {
        $cols['pageviews'] = 'Views';  
        return $cols;
    }
    add_filter( 'manage_edit-post_columns', 'kb_add_views_column' );
    
    function kb_add_views_colunm_data( $colname ) {
        // Make sure we're inserting into the correct column
        if ( 'pageviews' !== $colname )
            return false;
        echo do_shortcode( '[jp_post_view]' );
    }
    add_action( 'manage_posts_custom_column', 'kb_add_views_colunm_data' );


    • This reply was modified 2 years, 6 months ago by grumo64.
    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic 🚀

    I’m afraid this won’t be suitable for everyone, as it only populates views for the pages you’re looking at, and can lead to performance issues on sites where folks display more than 20 posts per page.

    Thanks for giving it a try though! If that’s enough for you, that’s perfect!

    Thread Starter grumo64

    (@grumo64)

    In fact I display 50 posts per page and work also for custom post type or page.
    I simply duplicate add_action/add_filter with corresponding post_type:

    //Where event is my custom post type
    add_filter( 'manage_edit-event_columns', 'kb_add_views_column' );
    add_action( 'manage_event_custom_column', 'kb_add_views_colunm_data' );

    https://developer.ww.wp.xz.cn/reference/hooks/manage_screen-id_columns/

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

The topic ‘How to change cache duration’ is closed to new replies.