12% off of LTD using this coupon: TWELVEPERCENTOFF. Promo ends on 2 Dec midnight UTC.
Published on Oct 10, 2022

Conditionally Outputting if Date Field’s Value is Not Older Than 7 Days

Sridhar Katakam

A member asked:

I need your help for a tutorial

How can I only show a div in Oxygen conditions when a ACF date field is not older dan 7 days?

We can define a custom function that compares the post's date-field value against the time a week ago and either return true or false. Then use it with the built-in Oxygen's Dynamic Data condition to output a Repeater Div or any element on the single post pages only if the post's date field falls in the last one week.

This premium tutorial walks you through the process.

First, create a field group with your favorite custom fields plugin like ACF/Meta Box or otherwise having a date-type of field. The field can also be of the type Date and Time as well.

The Display and Return formats do not matter and can be any.

Edit your posts and set the dates for each. If the field is empty, we will code the function such that it will return false so the element on which the condition is applied will not be output.

Add the following code in a custom functionality plugin or a code snippets plugin:

This is a premium members-only content.

To view the rest of the content, please sign up for membership ($47/month or $599 one-time).

Already a member? Log in below or here.

tagschevron-leftchevron-rightchainangle-rightangle-upangle-downfolder-omagnifiercrossmenuchevron-downarrow-right