Join the Soledad Facebook Users Group here
for Share, assistance, discussion, and Updates related to Soledad WordPress Theme.

If you can't create a new ticket - you can send us an email via our contact form and we will get back to you.

Okay
  Public Ticket #2628122
Popular Post Weekly / Monthly Conflict
Closed

Comments

  • webareca started the conversation

    Hi There,

    I use the popular post widget on the right sidebar on my website. First, Weekly and monthly options work exactly the opposite of each other. So when I choose weekly, it lists the monthly popular posts, and when I choose the monthly, the opposite sorts the weekly posts. Second, it sometimes shows monthly posts although I chose the weekly option. Can you help me solve the problem?


    Best,

  •  2,699
    PenciDesign replied

    Hi,

    Can you tell me how you can detect it showing most viewed posts monthly or weekly?


    Best Regards,

    PenciDesign

  • webareca replied

    Hi There,

    First, I look at the post's creation date. When I choose weekly popular posts, it shows posts that were posted 2-3 months in advance and listed by the number of reads. When I select monthly popular posts - although not exactly weekly - it shows more recent but not weekly ones. In general, I think you rank according to the number of readings, right?

    Best,

  •  2,699
    PenciDesign replied

    Hi,

    Yes, exactly.

    The popular posts on weekly will showing the most viewed posts in the last 7 days.

    The popular posts on monthly will showing the most viewed posts in the last 30 days.

    So, of course, it can be different. I just checked it from my-end and I see the counter is correct..

    Example: You have a post AA has published 3 months ago, but in this week, this post has many views, it still showing on the most viewed posts in the last 7 days.

    Best Regards,

    PenciDesign

  • webareca replied

    Hi,

    I think I just got the format. I was waiting for the most popular posts to be listed in the last week. As far as I understand, I cannot use this widget for that purpose. Is there a feature that we can sort by reading among the posts published in the last week? Thank you.

  • webareca replied

    Hi There, 

    One more thing, 

    In addition, since the posts in this section are featured, users constantly see them, which, as far as I understand, further increases their read count and creates a vicious circle. This prevents the list from being updated. What approach do you think I should take so that the list does not lose its dynamism?


    Best,

  •  2,699
    PenciDesign replied

    Hi,

    1/ Yeah, at this moment, it's not.

    2/ If so, I think you can try use random posts for Recent Posts widget, let's edit your recent posts widget, select order by to "Random" to make your posts display as random - I think it's better for your case.


    Best Regards,

    PenciDesign

  • webareca replied

    Hi There,


    I've realized that the reason why the weekly and monthly popular posts widget were not working properly is the penci_post_week_views_count and penci_post_month_views_count. The weekly counter is increasing parallel with the penci_post_views_count and the monthly counter is not acting like monthly.

    Could you please help me to resolve the situation?

    Thank you,


  •  2,699
    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