Problem with function "tribe_add_start_end_time_to_month_view "

Home Forums Calendar Products Events Calendar PRO Problem with function "tribe_add_start_end_time_to_month_view "

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #1363964
    Adam
    Participant

    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.

    #1363979
    Mathew
    Participant

    Adam,

    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.

    #1364846
    Cliff
    Member

    Mathew, 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.

    #1366732
    Adam
    Participant

    Hi,

    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.

    #1366838
    Cliff
    Member

    Adam, 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.

    #1367458
    Adam
    Participant

    This reply is private.

    #1367835
    Cliff
    Member

    Thanks 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.

    #1368301
    Adam
    Participant

    Hi 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.

    #1368390
    Cliff
    Member

    Please re-send the latest errors, then, because that Line 6 of functions.php doesn’t match up with my copy of Avada.

    #1368563
    Adam
    Participant

    This reply is private.

    #1368804
    Cliff
    Member

    Thanks. 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.

    #1369052
    Adam
    Participant

    This reply is private.

    #1369782
    Cliff
    Member

    Please 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.

    #1370664
    Adam
    Participant

    OK, many thanks for looking at this.

    #1371901
    Cliff
    Member

    You bet. Have a great week!

Viewing 15 posts - 1 through 15 (of 15 total)
  • The topic ‘Problem with function "tribe_add_start_end_time_to_month_view "’ is closed to new replies.