Help Desk

Javascript error on page possibly affecting event links.

  • Posts: 14 Topics: 6
    | Permalink

    Hi,

    So I wrote some custom code to place the events on the home page. I am also using that same code to create the events list page, by following the themer’s guide to create the new template and styles. The links to the events just redirect back to the homepage. Also if I try to go to the URL /event/test-event-3/, that fails as well. Do you have any suggestions as to how I can go about troubleshooting this?

    Also what would cause that php warning which is seen in both places? Or is that just because of the debugging in the staging environment?

    Here is a link to a gist of the code that I wrote:

    The theme I am working with was custom written for the site. I appreciate the help.

    Posts: 14 Topics: 6
    | Permalink

    Also if I remove my custom code for list.php the problem still persists.

    Posts: 18146 Topics: 17 Answers: 973
    | Permalink

    Hi Shea,

    The first thing I need to highlight here is that the level of support we can provide for custom dev tasks if really pretty limited. That said, I’ll try to steer you in the right direction if I can.

    With regards to the code you shared in your gist, you are grabbing an array of event posts via tribe_get_events() and then loop through them. Within that loop you then call tribe_get_event_link() but are not passing the ID of the event.

    Though that would still work in a “real” WordPress loop, in this case – despite the fact that you are calling setup_postdata() – the global post object is untouched by this:

    setup_postdata() does not assign the global $post variable so it’s important that you do this yourself. Failure to do so will cause problems with any hooks that use any of the above globals in conjunction with the $post global, as they will refer to separate entities.

    So, either ensuring the global post object is setup correctly or just explicitly passing the event ID ought to work 🙂

    strtotime() expects parameter 1 to be string, object given in /…/plugins/the-events-calendar/src/Tribe/Query.php on line 220

    I’m guessing the PHP warning above is the other problem you were referring to.

    My guess is that this stems from the start_date argument you are passing to tribe_get_events(): instead of passing a DateTime object, I’d recommend passing a date string such as “2016-12-31 12:00:00” instead.

    That leaves us with the JS error which seems to be coming from our This Week widget. I see it on your homepage, but can you confirm A) if the section entitled Coming Events is generated by that widget B) if it has itself been customized and C) if you are embedding it as a normal widget or via a shortcode?

    Thanks!

    Posts: 14 Topics: 6
    | Permalink

    Hi Barry,

    I was able to get the id passing through properly so the event page links are working properly. I also passed in

    $time = current_time( $type, $gmt = 0 );

    to get rid of the PHP warning. Thanks so much for the help.

    I am not sure if the current events is being generated by the widget behind the scenes. I haven’t done anything to edit the code myself. Everything that I wrote is in the gist I posted with the minor tweaks that I made based on your above suggestions. I am also seeing a new JS error in the tribe-events.min.js file :

    Uncaught TypeError: c(...).on is not a functiontribe_ev.fn.tooltips @ tribe-events.min.js?ver=4.0.4:1
    (anonymous function) @ tribe-events.min.js?ver=4.0.4:1
    c.extend.ready @ jquery.min.js?ver=4.4.1:26
    L @ jquery.min.js?ver=4.4.1:33

    Currently the site is running as I would expect, so I am not sure if these are bugs, or something in my code is causing them.

    Thanks,
    Rich

    Posts: 18146 Topics: 17 Answers: 973
    | Permalink

    On a clean site, with no customizations and only a default, unmodified theme – do you find the same JS errors occur?

    Could it be another plugin or your theme itself are conflicting?

    Posts: 14 Topics: 6
    | Permalink

    Hi Barry,

    It is the theme that is causing the error, if I switch to a default theme it goes away. The theme is custom, so I am not sure why that conflict would be created, but everything is still currently working.

    Thanks,
    Rich

    Posts: 18146 Topics: 17 Answers: 973
    | Permalink

    OK – are you happy to progress this on your own in that case (or with the developer who created the theme)? I’m not sure quite how much further assistance we’ll be able to provide here.

    Posts: 65
    | Permalink

    This topic has not been active for quite some time and will now be closed.

    If you still need assistance please simply open a new topic (linking to this one if necessary)
    and one of the team will be only too happy to help.