• Resolved gasmas75

    (@gasmas75)


    Hello all,
    Is there any way to display popular posts using the WPBakery’s “Post Grid” module? Maybe using a custom query with WPP data/variables?
    Or the only solution is to make a custom css and use the plugin’s shortcode on a plain column?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Hector Cabrera

    (@hcabrera)

    Hi @gasmas75,

    The plugin doesn’t offer native integration with WPBakery so yes you’ll have to customize the listing via CSS to turn it into a (responsive) grid.

    Thread Starter gasmas75

    (@gasmas75)

    Well i found a solution thanks to @radgh thread and custom function.
    Used his function and then used the meta-keys to get the data into WPBakery’s interface.
    @hcabrera I Used your variation i found in the thread to correct the over 1000 views issue.
    *To whoever it may concern –> Don’t forget to set the $accurancy to 100 for a while until you have a decent view count
    Thanks all

    Plugin Author Hector Cabrera

    (@hcabrera)

    Good work, @gasmas75!

    If possible, please consider sharing your solution. Other users might benefit from it.

    Thread Starter gasmas75

    (@gasmas75)

    I included the link to the thread, but for convenience this is the function I used in functions.php:

    /* Storing views of different time periods as meta keys */
    add_action( 'wpp_post_update_views', 'custom_wpp_update_postviews' );
    
    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 ) );
    	}
    }

    Then in WPBakery I used the meta-key of my choice (views_xxx) as custom sorting.
    Just remember as the function’s author (@radgh) mentioned to set $accuracy to 100 for the first clicks.

    Thread Starter gasmas75

    (@gasmas75)

    I already included the link on my previous post, but here it is for convenience:
    Use this function from @radgh:

    /* Storing views of different time periods as meta keys */
    add_action( 'wpp_post_update_views', 'custom_wpp_update_postviews' );
    
    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 ) );
    	}
    }

    Then in WPBakery’s post grid->Data Settings->Orderby->Meta Value enter the meta-key of your choice (views_xxxx)

    Thread Starter gasmas75

    (@gasmas75)

    I already included the link on my previous post, but here it is for convenience:
    Use this function from @radgh:

    /* Storing views of different time periods as meta keys */
    add_action( 'wpp_post_update_views', 'custom_wpp_update_postviews' );
    
    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 ) );
    	}
    }

    Then in WPBakery’s post grid->Data Settings->Orderby->Meta Value enter the meta-key of your choice (views_xxxx)

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Show popular posts with WPBakery post grid’ is closed to new replies.