Skip Navigation

[Resolved] displaying the start and end date only for events spanning more than 1 day

This support ticket is created 5 years, 1 month 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Tagged: 

This topic contains 11 replies, has 2 voices.

Last updated by digitalF 5 years, 1 month ago.

Assisted by: Nigel.

Author
Posts
#1388693

I'm using types and views to show a list of events by the Tribe Events plugin, which is working perfectly fine.

What I'm trying to do now is show both the start and and dates of the events, but only for the events spanning more than 1 day.

My views code is currently as follows:

[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>
<div class="event-card-container">
<div class="event-image">[wpv-post-featured-image size="medium"]</div>
<div class="event-content-box">
<div class="event-title">[my-title length="46"]</div>
<div class="event-date">[tribe-start-date]</div>
<div class="event-category">[types field='category-image' title='%%TITLE%%' alt='%%ALT%%' size='full'][/types]</div>

<div class="w-btn-wrapper width_auto align_center"><style>@media(max-width:600px){.us_btn_1{font-size:16px!important}}</style>Read More / Book</div>

</div>
</div>
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"]No items found[/wpml-string]
[/wpv-no-items-found]
<div class="pagination-feed-section">[wpv-pager-nav-links output="bootstrap"]</div>

[wpv-layout-end]

================================================================

In addition to this, I also have a custom code with the following:

<?php
/**
* New custom code snippet.
*/

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

add_shortcode('tribe-start-date', 'tribe_start_date_shortcode');
function tribe_start_date_shortcode() {
global $post;
return tribe_get_start_date( $post->ID, false, 'l dS F Y' );

}

================================================================

Ideally in the views, I would have the text display on the frontend as:

Friday 22nd November to Friday 30th November 2019 (again, only for events spanning for more then one day). For the events that are a single day it can simply display as: Friday 22nd November

Can you let me know how I would go about integrating this?

Many thanks

#1388791

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

If the Events Calendar API has a function tribe_get_start_date() I'm guessing it has a function tribe_get_end_date() as well, in which case it seems to me the solution would be in your custom shortcode tribe-start-date to get both, compare and see if they are equal, if yes, just return the start date as you do now, but if not return a string that shows start date to end date.

#1391613

okay that sounds good. How would I go about doing that?

#1391615
Screen Shot 2019-11-25 at 17.28.26.png

I have selected both the start/end dates options, the start date was selected previously.

#1391629

I've adjusted the start date short-code to the end date one to as follows (in the Settings > custom code section):

<?php
/**
* New custom code snippet.
*/

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

add_shortcode('tribe-end-date', 'tribe_end_date_shortcode');
function tribe_end_date_shortcode() {
global $post;
return tribe_get_end_date( $post->ID, false, 'l dS F Y' );

}

- but it hasn't worked. I just see: [tribe-end-date] in the view. My views code is as follows:

[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>
<div class="event-card-container">
<div class="event-image">[wpv-post-featured-image size="medium"]</div>
<div class="event-content-box">
<div class="event-title">[my-title length="46"]</div>
<div class="event-date">[tribe-start-date]</div>
<div class="event-date">[tribe-end-date]</div>
<div class="event-category">[types field='category-image' title='%%TITLE%%' alt='%%ALT%%' size='full'][/types]</div>

<div class="w-btn-wrapper width_auto align_center"><style>@media(max-width:600px){.us_btn_1{font-size:16px!important}}</style>Read More / Book</div>

</div>
</div>
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"]No items found[/wpml-string]
[/wpv-no-items-found]
<div class="pagination-feed-section">[wpv-pager-nav-links output="bootstrap"]</div>

[wpv-layout-end]

Any help is much appreciated.

#1392147

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

If you are seeing the shortcode printed rather than parsed then your code that registers it isn't running.

Double-check the code snippet that you added is active. I'm guessing that there is an API function tribe_get_end_date() available but you should confirm that with the Events Calendar documentation.

#1392175
Screen Shot 2019-11-26 at 09.06.08.png

HI,

There is and the code is active, see screenshot.

Any other ideas?

#1392191

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Can I look myself?

Even if the tribe_get_end_date was returning something unexpected, e.g. null or an error, you wouldn't see [tribe-end-date] printed.

I will mark your next reply as private so that I can get log-in credentials from you—you may want to create a temporary admin user for me to use that you can later delete. And be sure to have a current backup.

Which page has the View where you are using this?

#1392287

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Well, in that case you need only one shortcode, but you need to edit it as I described in my first reply, where you get both the start and end dates, compare them, and if they are the same, only return the start date, and if they are different return both.

Something like the following which registers a shortcode [tribe-dates]:

add_shortcode('tribe-dates', 'tribe_dates_shortcode');
function tribe_dates_shortcode()
{
    global $post;
    $output = '';

    $start = tribe_get_start_date($post->ID, false, 'l dS F Y');
    $end = tribe_get_end_date($post->ID, false, 'l dS F Y');

    if ( $start === $end ) {
        $output = $start;
    } else {
        $output = $start . ' to ' . $end;
    }

    return $output;
}
#1392295

Hi,

Thanks for that, I'm using the code you supplied with the short-code [tribe-dates]

However I'm only seeing the [tribe-dates] shortcode on the frontend.

The code was added via the snippets plugin and is active.

Any ideas?

#1392347

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

From your earlier replies where it seems it mysteriously started working I suspect it would be related to some caching mechanism on your site.

If the Code Snippets section of Toolset settings isn't working out very well for you, you can de-activate those and instead add the code to your theme's functions.php file at the end.

#1392365

Hi Nigel,

You are correct. Cleared cache and the edits are now showing.

My issue is resolved now. Thank you!