25th Sep '23
/
0 comments

Conditional Rendering Based on Current Date and Time in Bricks when Using Meta Box

A Pro member of our site asks:

Using bricks + Meta, conditionally show a post listing under 3 different conditions, based on the Current Date and Time… Would like to keep it simple, and use Radio for 3 options 1) Display Listing 24/7 2) Display during call center Hours (9-6EST) Monday To Friday 3) Display Only Monday To Friday (Hours not a concern)

This Pro tutorial shows how we can control the rendering of an element (a Top Banner Section in this example) depending on the value of a radio custom field on a Settings page when using Meta Box in Bricks.

  • 24/7: If this is selected, the banner will be shown (output) all the time.
  • Monday To Friday 9 am - 6 pm: If this is selected, the banner will be shown only during the weekdays between 9am and 6pm.
  • Monday To Friday anytime: If this is selected, the banner will be shown only during weekdays (anytime)
  • When no option is selected, the banner will not be output.

Step 1

Install Meta Box and Meta Box AIO plugins.

Go to Meta Box > Settings Pages and click New Settings Page.

Give it a title of say, "Sitewide".

Click Publish.

Step 2

Go to Meta Box → Custom Fields and create a new field group named say "Settings Page Fields".

Add a field like this (field export given below):

In the Settings tab, set the Location to your settings page.

Field Export json

Step 3

Click on Sitewide in the WP admin left menu and select an option.

Step 4

Edit your Header template with Bricks and add your Top Banner section above the header.

Step 5

At Settings → General, ensure that Timezone is set to the (closest) city in which the site's business run from.

Step 6

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

Get access to all 633 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
Filtering Bricks Query Loop By Meta Box Relationship

Filtering Bricks Query Loop By Meta Box Relationship

In the Bricks Facebook group a user asks: Consider this setup: CPTs: Service Areas and City Pages Meta Box Relationship: City Pages to Service Areas…
Categories:
Pro
Meta Box/ACF Images Staggered Grid Gallery in Bricks

Meta Box/ACF Images Staggered Grid Gallery in Bricks

Showing images from two Gallery-type of ACF or Image Advanced-type of Meta Box fields in a staggered grid layout.
Pro
Meta Box Color Picker to CSS Custom Property Workflow in Bricks

Meta Box Color Picker to CSS Custom Property Workflow in Bricks

This Pro tutorial provides the steps to declare a custom property (CSS variable) whose value is equal to the post-specific color set via a custom…
Categories:
Tags:
Pro
MB Favorite Posts in Bricks

MB Favorite Posts in Bricks

This tutorial explores using MB Favorite Posts in Bricks, including outputting the list of favorites via a query loop.
Categories:
Pro
Filtering Meta Box Cloneable Group by Select Subfield for Multiple Bricks Query Loops with Conditional Output

Filtering Meta Box Cloneable Group by Select Subfield for Multiple Bricks Query Loops with Conditional Output

In the Bricks Facebook group a user asks: Consider this cloneable Meta Box field group for a Custom Post Type called Tour: with the Tour…