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 610 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
Meta Box Taxonomy Field’s Image Value in Posts

Meta Box Taxonomy Field’s Image Value in Posts

In a project I am currently working on, the requirement is to show the image of an "Image Advanced" type attached to a taxonomy in…
Categories:
Tags:
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…
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
Custom Meta Box Thumbnail Slider in WordPress

Custom Meta Box Thumbnail Slider in WordPress

This Pro tutorial provides the steps to set up an image and YouTube video thumbnail slider in WordPress using Splide and Meta Box. The site…
Categories:
Tags:
Pro
Meta Box Group’s Number Sub Field Values Sum

Meta Box Group’s Number Sub Field Values Sum

In the Bricks Facebook group a user asked: We can define a custom function that takes a Meta Box group ID, the sub field ID…
Categories:
Tags: