Conditionally Outputting Query Loop Item Based on Post Meta in Bricks

Rendering query-loop enabled posts depending on the value of each post's custom field value is tricky because by default, the custom field plugins' functions or builder-functionality for fetching the custom field pulls the value of meta for the post (Post/Page/CPT/template etc.) in which the query loop element is present, not the individual posts in the loop.

In a previous Conditional Rendering Based on Current Date and Time in Bricks when Using Meta Box tutorial we showed how a non query loop element can be output based on a Radio field in a Settings page.

In this Pro tutorial we use a similar type of field, a Select field with the same choices and see how the posts can be output depending on the selected choice for each post.

Field group created using Meta Box for post post type:

A specific post being edited:

The above post should be output only if the current time is between 9 am and 6 pm on a weekday.

Step 1

Set up your query loop the usual way.

Step 2

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

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Instant access to 390+ Bricks code tutorials with BricksLabs Pro