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: https://toolset.com/forums/topic/conditionally-showing-content-based-on-the-event-start-date/#post-1112061

Relevant Documentation: https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/

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.

Auteur
Publications
#1111548
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.

Thanks,
Josh

#1112061

Minesh
Supporter

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"];
    if($format=='timestamp'){
           return strtotime($date);
     }else{
       return date($format, strtotime($date));
   }
}
add_shortcode("date-format", "func_date_format");

Where:
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
[/wpv-conditional]
#1113219

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