Posted: October 7, 2015 at 10:39 am
|
I’m using Ajax to load events near a person once their location has been determined. This is inside a wordpress framework, using the WordPress Ajax integration. However, my ajax function in functions.php dies when it tries to call an event espresso function. Here is the offending line:
If I take this line out, the rest of the function works perfectly. The code stops right when it gets to espresso_event_date(); Is there a reason why that function would not be available inside an ajax function? Please let me know if you need more info. |
Hi Adam, One thing you could check is if template_tags.php is loaded up when your AJAX call is made. A quick way to check is just copy the espresso_event_date function, including the function_exists() check, into your functions file. This will not cause a function already declared error, since the original function is wrapped in a function_exists() check. |
|
|
Copying that whole function into functions.php worked perfectly. What does that mean isn’t working correctly, and how can I fix it? |
One possibility is your code is executing before the WordPress init hook. If all you need is the espresso_event_date() tag, then what you’ve already done is sufficient to fix it. If you need more template tags, you can add them to your function. You can also open up Event Espresso core in an IDE and step through the code where Event Espresso loads up each system when needed. What you’ll find is Event Espresso doesn’t load everything all at once, instead, it loads up its systems step by step and when needed. |
|
|
Hmm, ran into a problem — the problem is that that function references other EE functions … which are also not available. So, I added this line to my functions.php to force it to load: Is that going to cause problems elsewhere with EE? |
You can prevent potential problems by checking for any variables, functions or classes defined in the include file and see if it’s already included. For example:
Then you also test your code to make sure it doesn’t cause problems elsewhere. |
|
The support post ‘Using Event Espresso Functions inside Ajax in WordPress’ is closed to new replies.
Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.