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 support ticket is created Il y a 6 années et 2 mois. 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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

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)

Marqué : ,

Ce sujet contient 2 réponses, a 2 voix.

Dernière mise à jour par joshM-4 Il y a 6 années et 2 mois.

Assisté par: 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

Les langues: Anglais (English )

Fuseau horaire: 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!