We are increasing the price on 14th may 2024. 

Premium add-on for Bricks Builder

Display All Sticky Posts with Query Loop

In this tutorial, I shall show you how you will display the sticky posts with the Bricks’ Query Loop builder.

Step 1: Add a container on the canvas and enable the “Use query loop” option. you’ll see a Query control. This is where you will set the arguments for the query loop. Here are my settings

Make sure that you enable the “Ignore sticky posts” option.

Set Posts per page = -1 or 999 if you want to show all posts.

Step 2: Add the nested elements like featured image, post title, date, excerpt, etc inside the query loop builder container and make the layout. Publish the changes.

Step 3: Open the functions.php file of the Bricks child theme or you can place the code on a 3rd party plugin if you are using anyone.

add_filter( 'bricks/posts/query_vars', 'bu_show_sticky_posts', 12, 3 );
function bu_show_sticky_posts( $query_vars, $settings, $element_id ) {
        /** 
	 * pilbnn is my query loop builder's container ID.
	 * You will change it with yours one
	 * 
	 * So this code will not apply to entire site
	 */
	if( $element_id == 'pilbnn' ) {
		$query_vars['post__in'] = get_option('sticky_posts');
	}

	return $query_vars;
}
Element ID
Element ID

The Bricks builder is giving the filter. So you can overwrite the default arguments with custom PHP code. I used that filter and altered the query arguments.

get_option(‘sticky_posts’) is returning the all sticky posts ID as an array.

Now refresh the bricks builder editor and you see the preview there. You can also see the result at frontend.

Fills In: 

Leave the first comment

Search Tutorials

Request TutorialsFeatures Request