PenciDesign replied
Hi,
If your popular posts weekly/monthly data can't be updated - that means your hosting doesn't support function: wp_schedule_event from WordPress. It makes the post data can't be removed after each week/month.
Here are our codes to process to clear post views after each week/month:
/**
* Add schedules intervals
*
* @since 2.5.1
*
* @param array $schedules
*
* @return array
*/
add_filter( 'cron_schedules', 'penci_add_schedules_intervals' );
if ( ! function_exists( 'penci_add_schedules_intervals' ) ) {
function penci_add_schedules_intervals( $schedules ) {
$schedules['weekly'] = array(
'interval' => 604800,
'display' => __( 'Weekly', 'soledad' )
);
$schedules['monthly'] = array(
'interval' => 2635200,
'display' => __( 'Monthly', 'soledad' )
);
return $schedules;
}
}
/**
* Add scheduled event during theme activation
*
* @since 2.5.1
* @return void
*/
add_action( 'after_switch_theme', 'penci_add_schedule_events' );
if ( ! function_exists( 'penci_add_schedule_events' ) ) {
function penci_add_schedule_events() {
if ( ! wp_next_scheduled( 'penci_reset_track_data_weekly' ) )
{wp_schedule_event( time(), 'weekly', 'penci_reset_track_data_weekly' );}
if ( ! wp_next_scheduled( 'penci_reset_track_data_monthly' ) )
{wp_schedule_event( time(), 'monthly', 'penci_reset_track_data_monthly' );}
}
}
/**
* Remove scheduled events when theme deactived
*
* @since 2.5.1
* @return void
*/
add_action( 'switch_theme', 'penci_remove_schedule_events' );
if ( ! function_exists( 'penci_remove_schedule_events' ) ) {
function penci_remove_schedule_events() {
wp_clear_scheduled_hook( 'penci_reset_track_data_weekly' );
wp_clear_scheduled_hook( 'penci_reset_track_data_monthly' );
}
}
/**
* Reset view counter of week
*
* @since 2.5.1
* @return void
*/
add_action( 'penci_reset_track_data_weekly', 'penci_reset_week_view' );
if ( ! function_exists( 'penci_reset_week_view' ) ) {
function penci_reset_week_view() {
global $wpdb;
$meta_key = 'penci_post_week_views_count';
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->postmeta SET meta_value = '0' WHERE meta_key = %s", $meta_key ) );
}
}
/**
* Reset view counter of month
*
* @since 2.5.1
* @return void
*/
add_action( 'penci_reset_track_data_monthly', 'penci_reset_month_view' );
if ( ! function_exists( 'penci_reset_month_view' ) ) {
function penci_reset_month_view() {
global $wpdb;
$meta_key = 'penci_post_month_views_count';
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->postmeta SET meta_value = '0' WHERE meta_key = %s", $meta_key ) );
}
}
You can contact your hosting provider and requirement them fix it to help you.
We've checked it many times before to make sure this function working well. I saw some customers have this issue before because their hosting doesn't support it.
Best Regards,
PenciDesign