Syntax needed for conditional code within Event List shortcodes

WordPress Event Management, Calendars & Registration Forums General Question Syntax needed for conditional code within Event List shortcodes

This topic contains 4 replies, has 2 voices, and was last updated by  Stephen Harris 2 years, 6 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #41319

    I have submitted this query 3 times already, and it looks like 3 times have failed.

    I’m able to “reply” to my own apparently empty query yet the forum software keeps vapourising, the body of my query, apparently.

    I have a saved copy… so I’m now going to try stripping the markup and resubmitting… to finally get through on here.

    Vicki Taylor
    #41322

    Hi, Stephen,

    I’ve already attempted to submit this query so many times, but it keeps getting blocked… so I keep stripping markup, hoping to clean it up enough to “go in”. Fingers crossed it works this time!

    I’m getting tremendous mileage from the event_list %event_organiser_url% code you gave me – https://wp-event-organiser.com/forums/topic/event-list-shortcode-include-organiser-wp-username-linking-website/. I use it in various lists with the format tweaked for specific event categories. Great!
    Thank you! šŸ˜€

    Alas, Iā€™m still not very code-clue-ful, so I need a tiny bit more help with conditional code. In some lists, I mix more-than-one category, and want to mix organisers: with, and without, %event_organiser_url%

    So in this example:
    [eo_events event_category=”introduction,intermediate,review” showpastevents=”true” event_start_after=”first day of january this year” event_end_before=”first day of january next year” no_events=”No events announced at present”]%start{j F}% – %end{j F}%: [%event_title%] led by [%event_organiser%][/eo_events]

    Please give me the syntax for these 3 conditions:

    1) IF event_category=”introduction,intermediate”, show:
    led by [%event_organiser%]
    if event_category=”review”, don’t show it.

    2) IF %event_organiser% is exactly “some-user”, don’t show: led by [%event_organiser%]
    but for the remainder, show it.

    3) AND IF other users’ %event_organiser_url% is not empty, show:
    led by [%event_organiser%]
    otherwise, only show: led by %event_organiser%

    Thanking you in advance for all your very kind help!<br />
    Vicki

    Vicki Taylor
    #41356

    Hi Vicki,

    Apologies that your posts kept being blocked.

    Unfortunately the templating doesn’t extend to supporting conditional logic. This can be done in PHP. Specifically if you use the shortcode without any templating and then copy the file event-organiser/template/shortcode-event-list.php into your theme, and edit line 48.

    Something like the following should work (although I’ve not tested it):

    <?php
    $event = get_post();
    $event_organiser = get_user_by( 'id', (int) $event->post_author );
    $event_organiser_url = esc_url($event_organiser->user_url);
    
    printf( "%s - %s: %s", eo_get_the_start( "j F" ), - eo_get_the_end( "j F" ), get_the_title())
    
    if ($event_organiser->user_login != "some-user" && ! has_term("review", "event-category") ) {
      if (empty($event_organiser_url)) {
         printf( " led by %s", esc_html($event_organiser->display_name));
      } else {
         printf( " led by <a href="%s">%s</a>", $event_organiser_url, esc_html($event_organiser->display_name))
      }
    }
    ?>
    
    Stephen Harris
    #41318

    Hi, Stephen,

    I’ve already attempted to submit this query twice, but it seems both times failed, so here I go again!

    I’m getting tremendous mileage from the event_list %event_organiser_url% code you gave me – https://wp-event-organiser.com/forums/topic/event-list-shortcode-include-organiser-wp-username-linking-website/. I use it in various lists with the format tweaked for specific event categories. Great! Thank you! šŸ˜€

    Alas, Iā€™m still not very code-clue-ful, so I need a tiny bit more help with conditional code.

    In some lists, I mix more-than-one category, and organisers with and without URLs.

    So in this example:

    [eo_events event_category="introduction,intermediate,review" showpastevents="true" event_start_after="first day of january this year" event_end_before="first day of january next year" no_events="No events announced at present"]<strong>%start{j F}% - %end{j F}%:</strong> <a href="%event_url%">%event_title%</a> <em>led by <a href="%event_organiser_url%">%event_organiser%</a></em>[/eo_events]
    

    Please give me the syntax for these 3 conditions?

    1) IF event_category=”introduction,intermediate”, show:

    <em>led by <a href="%event_organiser_url%">%event_organiser%</a></em>
    

    if event_category=”review”, don’t show it.

    2) IF %event_organiser% is exactly “some-user”, don’t show:

    <em>led by <a href="%event_organiser_url%">%event_organiser%</a></em>
    

    but for the remainder, show it.

    3) AND IF other users’ %event_organiser_url% is not empty, show:

       <em>led by <a href="%event_organiser_url%">%event_organiser%</a></em>
    

    otherwise, only show:

    <em>led by %event_organiser%</em>
    

    Thanking you in advance for all your very kind help!
    Vicki

    Vicki Taylor
    #41358

    Hi Vicki,

    Looks like our messages crossed. I had seen your earlier post but it had been marked as ‘pending’ by the forum.

    Does my answer help at all?

    Stephen Harris
Viewing 5 posts - 1 through 5 (of 5 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.