Post Views Counter Query Loop in Bricks

Looking to output the most viewed posts in your Bricks site in a query loop?

Install and activate the free Post Views Counter plugin.

Select post types for which post views will be counted in the plugin’s settings. It is enable for post by default.

In the Bricks editor, set up a query loop on a Block element, enable the PHP query editor in the query popup and paste:

return [
	'post_type' => 'post',
	'posts_per_page' => 3,
	'no_found_rows' => true,
	// required by PVC
	'suppress_filters' => false,
	'orderby' => 'post_views',
	'fields' => ''

Adjust the post type and posts per page as needed.

To output the number of views, use this dynamic data tag:


Sample Section JSON (ACSS variables were used).

If you would like to output an unordered list of post title links using the plugin’s function, use:



Instant access to 390+ Bricks code tutorials with BricksLabs Pro

Leave the first comment