Skip Navigation

[Résolu] Conditionally showing content based on the event start date

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem: Conditionally showing content based on the event start date

Solution: 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 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.

Marqué : ,

This topic contains 2 réponses, has 2 voix.

Last updated by joshM-4 Il y a 3 années et 1 mois.

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: Anglais (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!