Support

Home Forums Event Espresso Premium Ajax request return data doesn't include EE_Event information in post data

Ajax request return data doesn't include EE_Event information in post data

Posted: June 12, 2018 at 8:24 am


Damian Way

June 12, 2018 at 8:24 am

Hi there,

I posted a while back about my site not returning EE_Event data when retrieving post information:

https://eventespresso.com/topic/cant-create-instance-of-ee_event-since-update/

I haven’t managed to revolve this but have narrowed it down to being related to the calls being made via an Ajax request. If I run the below code normally within a pageload it runs fine and extends the post object to include the EE_Event object.


$wp_query = get_posts(array('post_type'=>'espresso_events','suppress_filters'=>false));
        var_dump($wp_query);

But if I call the same code via an Ajax request using WordPresses admin-ajax.php functions it isn’t including the EE_Event object. This used to work prior to the last update.

My Javascript is:

 
$( '.home select[name="course_name"]' ).live('change',function() {
		  //start search button spinner
			$('input[type=submit]#searchsubmit').hide();
			$('#spinner').show();
		  var courses_select = $('select[name="course_name"]');
		  var venues_select = $('select[name="venue"]');
                  venues_select.attr("disabled",true);
		  //get sub category values
		  //get tags
		  var data = {
			'action': 'sts_search_course_name',
			'course_slug': courses_select.val()
			};
			// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
			$.post(ajaxurl, data, function(response) {
var results = JSON.parse(response); 

                                        if(results['error'] === 'no results'){
                                                alert('No results found');
                                                $('#spinner').hide();
                                                $('input[type=submit]#searchsubmit').show();  
                                        }else{
                                                //remove current options
                                                venues_select.find('option').remove();
                                                venues_select.append($("<option></option>")
                                                                    .attr("value","")
                                                                    .text("Choose one"));
                                                //set up venues
                                                $.each(results['venues'], function(k){
                                                    venues_select.append($("<option></option>")
                                                                    .attr("value",results['venues'][k].ID)
                                                                    .text(results['venues'][k].post_title));
                                                });
                                                venues_select.removeAttr("disabled"); 
                                                $('#spinner').hide();
                                                $('input[type=submit]#searchsubmit').show();    
                                        }
				
			});
		  
		  
	});

And my callback function fails even if I just run:


function sts_search_course_name_callback(){
    $wp_query = get_posts(array('post_type'=>'espresso_events','suppress_filters'=>false));
        var_dump($wp_query);
}

Any ideas on why this may be?

Really appreciate the help and sorry about the long delay in response, been away for a few weeks and only just picked this up again. All plugins and WordPress are up to date.

Thanks

Damian


Josh

  • Support Staff

June 12, 2018 at 11:19 am

Hi Damian,

I’m not sure the problem would be with the JavaScript code, but it might help if you can post the contents of the form code into a gist and post a link here so we can investigate further.

Before you do that though, you might try adding this just before you call get_posts()


remove_all_filters('posts_where');
remove_all_filters('posts_join');


Damian Way

June 13, 2018 at 5:00 am

Hi Josh,

I have tried the callback as:


function sts_search_course_name_callback(){
remove_all_filters('posts_where');
remove_all_filters('posts_join');
$wp_query = get_posts(array('post_type'=>'espresso_events','suppress_filters'=>false));
var_dump($wp_query);
}

Still returning the post data with no event object. Is that what you meant?

I will see if I can set up a jist with the concept.

If it helps the live site code is here STS First Aid The test site is using the same forms, the form is the quick course search found under the slideshow.

The updated event espresso I am working on isn’t live yet, it’s on my local machine. Only differences are that the plugins and wordpress core have been updated on my test site.

Thanks for your help.


Tony

  • Support Staff

June 14, 2018 at 5:38 am

Hi Damian,

I’ve reproduced this using Debug Bar Console running the code you posted above:

$wp_query = get_posts(array('post_type'=>'espresso_events','suppress_filters'=>false));
var_dump($wp_query);

As you mentioned, in the current version of EE no EE_Event object is returned so I’ve created a ticket for our developers to investigate this further.


Damian Way

June 18, 2018 at 7:22 am

Thanks Tony, appreciate you guys taking the time out to look into it for me.

Do you know roughly how long this type of thing takes to develop a patch for? We currently can’t update to the latest version as it breaks some of our site features. Not putting pressure on just wanted to know so that I can plan accordingly.


Tony

  • Support Staff

June 18, 2018 at 10:18 am

Hi Damian,

Whilst I can’t give you a timeline currently, I can tell you that a developer has investigated the problem and has some changes that are currently under review, once reviewed (if approved) it will go out for testing and be merged into master ready to be included in the next release (as long as no issues are found with the changes).

I can send you a copy of the fixed branch if you’d like to test the changes?


Damian Way

June 20, 2018 at 11:52 am

Hi Tony,

Yes please, this would allow us to patch it in the mean time. Thanks for the update.


Josh

  • Support Staff

June 20, 2018 at 12:43 pm

The branch can be download from Github:

https://github.com/eventespresso/event-espresso-core/tree/BUG/event-object-ajax-requests


Josh

  • Support Staff

June 26, 2018 at 1:02 pm

Update: Event Espresso 4.9.64.p was released today and it includes a fix for the issue you reported here.


Damian Way

June 28, 2018 at 3:31 am

Perfect, thanks for the support guys.


Tony

  • Support Staff

June 28, 2018 at 4:08 am

You’re most welcome, please do let us know if you run into any further problems.

The support post ‘Ajax request return data doesn't include EE_Event information in post data’ 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.

Event Espresso