Skip Navigation

[Resolved] Conditionally showing content based on the event start date

This thread is resolved. Here is a description of the problem and solution.

Conditionally showing content based on the event start date

You can use [wpv-conditional] shortcode to compare the custom shortcode value.

You can find the proposed solution, in this case, with the following reply:

Relevant Documentation:

This support ticket is created 4 years, 4 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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by joshM-4 4 years, 4 months ago.

Assigned support staff: Minesh.

Screen Shot 2018-09-19 at 8.38.53 AM.jpg
Screen Shot 2018-09-19 at 8.38.35 AM.jpg

I have a view that displays events based on the specified event category in it's shortcode. I would like to limit the view to only show events that are today or in the future.

The field I'm trying to base this on is the _EventStartDate field (generated by Modern Tribe Events Calendar Pro plugin) that I've pulled in via the Hidden Custom Fields area, but I've not been able to get it to work.

Initially I tried modifying the query filter in the view, and then tried setting a conditional statement around the content inside the view loop. But I've been successful with neither (see screenshots).

Worth mentioning: I had to use a separate function/shortcode to get the date to display the way I wanted originally. Here's that function and the shortcode I used with it:

// The Function
function func_date_format($atts) {
		global $post;
    $format = $atts["format"];
    $date = $atts["date"];
    return date($format, strtotime($date));
add_shortcode("date-format", "func_date_format");

// The Shortcode
[date-format date="[wpv-post-field name='_EventStartDate']" format="F j"]

I'm hoping you can help me figure out what I'm doing wrong.




Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

The thing is that _EventStartDate stores the date value as date string and we need timestamp to compare the date so we need to convert the date string to the timestamp.

please replace the shortcode you are using with following to your functions.php file.

function func_date_format($atts) {
        global $post;
    $format = $atts["format"];
    $date = $atts["date"];
           return strtotime($date);
       return date($format, strtotime($date));
add_shortcode("date-format", "func_date_format");

Please register date-format above shortcode at:
=> Toolset => Settings => Front-end content tab => Third-party shortcode arguments

And user the conditional statement as given under inside your view's loop:

[wpv-conditional if="( '[date-format date='[wpv-post-field name='_EventStartDate']' format='timestamp']' gte NOW() ) "]
your content goes here

Minesh, this worked like a charm - thank you so much for the help!