Skip Navigation

[Resolved] Conditional to show something if a post is less than 7 days old

This support ticket is created 3 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by nickH-5 3 years, 10 months ago.

Assisted by: Waqar.

Author
Posts
#1853205

Could you tell me what is wrong with this conditional to show something if a post is less than 7 days old? [wpv-post-date format="U"][wpv-conditional if="( '([wpv-post-date format="u"]+(7*24*60*60))' gt 'NOW()' )"]NEW[/wpv-conditional]

#1853243

Hi,

During troubleshooting, I noticed two issues with the conditional block that you've shared:

1. The small 'u' was used in the format attribute and not the capital 'U', which represents the UNIX timestamp.
( hidden link )

2. The sum and multiplication operation can't be performed within the conditional evaluation.

To achieve this you can register a custom shortcode that can return the post date with the addition of 7 days. For example:


add_shortcode('seven_day_check', 'seven_day_check_func');
function seven_day_check_func() {
	$post_date = do_shortcode('[wpv-post-date format="U"]');
	$post_date_plus_7 = intval($post_date)+ intval(7*24*60*60);

	return $post_date_plus_7;
}

The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through active theme's "functions.php" file.

Next, please add "seven_day_check" in the "Third-party shortcode arguments" section, at WP Admin -> Toolset -> Settings -> Front-end Content.

After that, you'll be able to use this new shortcode in a conditional check, like this:


[wpv-conditional if="( '[seven_day_check]' gt 'NOW()' )"]NEW[/wpv-conditional]

regards,
Waqar

#1853251

Thanks. I didn't understand that it was not possible to evaluate in a condition.

This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.