Random Users Query Loop in Bricks

Looking to show users in random order when using a Users type of query in Bricks?

Add the following in child theme‘s functions.php or a code snippets plugin:

add_action( 'pre_user_query', function( $query ) {
	if ( $query->query_vars['orderby'] === 'rand') {
		$query->query_orderby = 'ORDER BY RAND()';
	}
} );

add_filter( 'bricks/users/query_vars', function( $query_vars, $settings, $element_id ) {
	if ( $element_id === 'yslvlr' ) {
		$query_vars['orderby'] = 'rand';
	}
	
	return $query_vars;
}, 10, 3 );

Replace yslvlr with the Bricks ID of your query loop element.

References

https://gist.github.com/siteoptimo/9049115

https://academy.bricksbuilder.io/article/filter-bricks-users-query_vars/

Get access to all 524 Bricks code tutorials with BricksLabs Pro

2 comments

  • Looking to show users in random order when using a Users type of query in.

  • Now I can go to any post / page / custom post type in my website, change the dropdown for this ACF field to page-builder and, in doing so, I can override the Single – Default template and design full-width using Bricks.

Leave your comment

 

Related Tutorials..

How to Exclude Elements from Bricks Editor

How to Exclude Elements from Bricks Editor

Bricks has a handy bricks/builder/elements filter using which the available elements that show up after clicking + (or ⌃/⌘ + ⇧ + E) in the…
Categories:
Tags:
Filtering out Media Items from “Select post/page” Bricks control

Filtering out Media Items from “Select post/page” Bricks control

The dropdown that appears after choosing "Internal post/page" when setting a link in Bricks shows media (attachment) items besides Pages, Posts and other CPTs. If…
Removing Action/Filter Inside a Plugin’s Namespaced Class Constructor

Removing Action/Filter Inside a Plugin’s Namespaced Class Constructor

Recently worked with a friend figuring out how to remove/undo/cancel an add_action() line that's inside a plugin's constructor inside a PHP Class with the file…
Categories:
Tags:
Modifying ACF Field Value Before It Is Output

Modifying ACF Field Value Before It Is Output

Consider the scenario where a Page has a "Page Fields" field group created with ACF Pro like this: Field name: scientific_coordinators (type Repeater)|__ Sub field…
Categories:
Pro
Setting a Bricks template for Parent pages

Setting a Bricks template for Parent pages

This Pro tutorial shows how bricks/active_templates filter can be used to programmatically assign a Bricks template to all singular pages (of any post type) that…
Pro
Limit the Number of Posts in a Bricks Query Loop of Relationship Type

Limit the Number of Posts in a Bricks Query Loop of Relationship Type

Updated on 12 Dec 2023 Bricks Query Loop popup does not have a control for setting the number of posts to be output when the…