Site logo

Archived topic

Wordpress Popular Posts Plugin with Generatepress?

1 reply · Started by Ahmed on July 19, 2022

Viewing posts 1–2 of 2

Hi there,

Wordpress Popular Posts is a plugin that shows popular posts in the last 1 day, week, month, etc. Unfortunately I find it hard to customize its CSS and I want to somehow show it with Generatepress. I've read about WP Show Posts but not sure how to pull this off.

They provide this code:

/**
 * Stores views of different time periods as meta keys.
 *
 * @author  @migueleste / @radgh
 * @link    https://wordpress.org/support/topic/how-to-sort-a-custom-query-by-views-all-time-monthly-weekly-or-daily/
 * @param   int     $postid     The ID of the current post/page/custom post type.
 */
function custom_wpp_update_postviews($postid) {
    // Accuracy:
    //   10  = 1 in 10 visits will update view count. (Recommended for high traffic sites.)
    //   30  = 30% of visits. (Medium traffic websites.)
    //   100 = Every visit. Creates many db write operations every request.

    $accuracy = 50;

    if ( function_exists('wpp_get_views') && (mt_rand(0,100) < $accuracy) ) {
        // Remove or comment out lines that you won't be using!!
        update_post_meta(
            $postid,
            'views_total',
            wpp_get_views($postid, 'all', false)
        );
        update_post_meta(
            $postid,
            'views_daily',
            wpp_get_views($postid, 'daily', false)
        );
        update_post_meta(
            $postid,
            'views_weekly',
            wpp_get_views($postid, 'weekly', false)
        );
        update_post_meta(
            $postid,
            'views_monthly',
            wpp_get_views($postid, 'monthly', false)
        );
    }
}
add_action('wpp_post_update_views', 'custom_wpp_update_postviews');

You can find it here as well: https://wordpress.org/support/topic/how-to-sorting-a-custom-query-by-views-all-time-monthly-weekly-or-daily/

But I'm not sure if this can help with anything?

Hi there,

WP Show Posts or the new Query Loop block from GenerateBlocks don't include the logic to determine which posts are "popular".

I would say that using the plugin + CSS is your best bet.

Otherwise you will need to create your own custom solution which is out of the scope of this forum.

You can try posting the question in a WordPress general forum like this one:
https://wordpress.stackexchange.com/

Good luck!

This archived topic is closed to new replies.