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]
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
Thanks. I didn't understand that it was not possible to evaluate in a condition.