Home › Forums › Calendar Products › Events Calendar PRO › Problem with function "tribe_add_start_end_time_to_month_view "
- This topic has 15 replies, 4 voices, and was last updated 6 years, 5 months ago by Cliff.
-
AuthorPosts
-
October 15, 2017 at 11:55 am #1363964AdamParticipant
Hi Support Team,
Since 2015 I’ve been using the following code snippet in my themes function.php file. It is to add the start time to the event title in the calendar month view. Up until recently, this has been working just fine.
/*
* START – Adds start time to event titles in Month view
*/
function tribe_add_start_time_to_event_title ( $post_title ) {/*if ( !tribe_is_event($post_id) ) return $post_title;*/
// Checks if it is the month view, modify this line to apply to more views
if ( !tribe_is_month() ) return $post_title;/*$event_start_time = tribe_get_start_time( $post_id );*/
if ( !empty( $event_start_time ) ) {
$post_title = $event_start_time . ‘ – ‘ . $post_title;
}return $post_title;
}
add_filter( ‘the_title’, ‘tribe_add_start_time_to_event_title’, 100, 2 );/*END – Adds start time to event titles in Month view */
Now I find that the time still displays correctly in the month overview, however it seems that on some but not all posts, when a user clicks the title to drill down into the event, they receive the error shown below. Going by the error it looks as though the code is expecting two variables to be passed into it but is not receiving them.
To keep the website running, I’ve temporarily removed this section of code but it is really critical that the start time is easily seen in the month overview.
Fatal error: Uncaught ArgumentCountError: Too few arguments to function tribe_add_start_time_to_event_title(), 1 passed in /home/sites/4b/b/b559d673c8/public_html/wp-includes/class-wp-hook.php on line 298 and exactly 2 expected in /home/sites/4b/b/b559d673c8/public_html/wp-content/themes/Avada/functions.php:114 Stack trace: #0 /home/sites/4b/b/b559d673c8/public_html/wp-includes/class-wp-hook.php(298): tribe_add_start_time_to_event_title(‘IXION Chapter 2…’) #1 /home/sites/4b/b/b559d673c8/public_html/wp-includes/plugin.php(203): WP_Hook->apply_filters(‘IXION Chapter 2…’, Array) #2 /home/sites/4b/b/b559d673c8/public_html/wp-content/themes/Avada/includes/class-avada-breadcrumbs.php(490): apply_filters(‘the_title’, ‘IXION Chapter 2…’) #3 /home/sites/4b/b/b559d673c8/public_html/wp-content/themes/Avada/includes/class-avada-breadcrumbs.php(211): Avada_Breadcrumbs->get_post_ancestors() #4 /home/sites/4b/b/b559d673c8/public_html/wp-content/themes/Avada/includes/class-avada-breadcrumbs.php(168): Avada_Breadcrumbs->prepare_brea in /home/sites/4b/b/b559d673c8/public_html/wp-content/themes/Avada/functions.php on line 114
Best regards,
Adam.October 15, 2017 at 2:35 pm #1363979MathewParticipantAdam,
It looks like your function is missing the second argument, $post_id.
Have a look at this snippet (line 4) to see the missing argument. I would copy and paste directly from the article into your custom functions or custom plugin.
Hope this helps.
October 17, 2017 at 10:41 am #1364846CliffMemberMathew, thanks for helping here.
Adam, Mathew’s advice looks sound. Change this:
function tribe_add_start_time_to_event_title ( $post_title ) {
to this:
function tribe_add_start_time_to_event_title ( $post_title, $post_id ) {
and see if that solves the issue for you.
October 20, 2017 at 11:42 am #1366732AdamParticipantHi,
Thanks for the reply from both of you.
I’ve added the following but still get the same result. Some but not all recurring events return a fatal error when clicked./*
* Adds start time to event titles in Month view
*/
function tribe_add_start_time_to_event_title ( $post_title, $post_id ) {if ( !tribe_is_event($post_id) ) return $post_title;
// Checks if it is the month view, modify this line to apply to more views
if ( !tribe_is_month() ) return $post_title;$event_start_time = tribe_get_start_time( $post_id );
if ( !empty( $event_start_time ) ) {
$post_title = $event_start_time . ‘ – ‘ . $post_title;
}return $post_title;
}
add_filter( ‘the_title’, ‘tribe_add_start_time_to_event_title’, 100, 2 );I’ve just tried with the theme 2015, and it seems to work with one of the recurring events that causes a problem when using the Avada theme. Avada say that they are compatible with Events Calendar. Any ideas where to go from here?
Best regards,
Adam.October 20, 2017 at 1:36 pm #1366838CliffMemberAdam, I tested your code with Twenty Seventeen and clicked about a dozen events–some recurring, some not–from Month View, and they all loaded the Event Single Page just fine.
As far as failing with Avada goes, all I can suggest is that you enable WP_DEBUG and WP_DEBUG_LOG (which will create a file on your server at /wp-content/debug.log if there are any WP_DEBUG messages) and share any debug messages you see while trying to replicate this issue.
October 23, 2017 at 4:14 am #1367458AdamParticipantThis reply is private.
October 23, 2017 at 7:26 pm #1367835CliffMemberThanks for sharing the errors. I’m guessing you don’t have the latest version of all Avada files. Please update the theme, apply all patches, and update the included plugins as well. Then, let me know if you’re still getting these errors.
October 24, 2017 at 12:20 pm #1368301AdamParticipantHi Cliff,
Many thanks for getting back to me. I can confirm that Avada is up to date along with the latest patches and plugins and I’m still getting the errors.
Best regards,
Adam.October 24, 2017 at 4:13 pm #1368390CliffMemberPlease re-send the latest errors, then, because that Line 6 of functions.php doesn’t match up with my copy of Avada.
October 25, 2017 at 5:15 am #1368563AdamParticipantThis reply is private.
October 25, 2017 at 10:53 am #1368804CliffMemberThanks. The issue is with Line 490 of /wp-content/themes/Avada/includes/class-avada-breadcrumbs.php, which is:
$ancestors_markup .= $this->get_single_breadcrumb_markup( apply_filters( 'the_title', $post_ancestor->post_title ), get_permalink( $post_ancestor->ID ) );
Notice they run apply_filters… I think they meant to run add_filter instead.
Please change that in your site just to test and see if your WP_DEBUG errors go away.
October 26, 2017 at 3:45 am #1369052AdamParticipantThis reply is private.
October 26, 2017 at 8:35 pm #1369782CliffMemberPlease report the issue to Avada. I have been glad to help thus far, but we really don’t provide debugging support for themes, per our Scope of Support / Terms.
October 28, 2017 at 8:49 am #1370664AdamParticipantOK, many thanks for looking at this.
October 30, 2017 at 8:28 pm #1371901CliffMemberYou bet. Have a great week!
-
AuthorPosts
- The topic ‘Problem with function "tribe_add_start_end_time_to_month_view "’ is closed to new replies.