Support

Home Forums Event Espresso Premium Load More Button Via Ajax and Custom Event Espresso Query

Load More Button Via Ajax and Custom Event Espresso Query

Posted: December 19, 2016 at 12:58 pm


fjorgeDigital

December 19, 2016 at 12:58 pm

Hello,
I am trying to run a custom query that uses ajax to load more events based on some custom taxonomy filters. The issue is that when I use the Event Espresso query (EE_Event_List_Query) versus. the normal WordPress query I can’t access the ‘paged’ parameter in order to return the results I want. I see that the Espresso query has the ‘limit’ parameter but this doesn’t work when I try to load things via ajax, as it just keeps loading the 1st “page” every time, as the ‘limit’ acts more as the posts_per_page parameter. Here is my query:

$arrParams = array(
‘post_type’ => array(‘espresso_events’),
‘limit’ => 5,
‘suppress_filters’ => false,
‘sort’ => ‘ASC’,
‘order_by’ => ‘start_date’,
);

global $wp_query;
$new = new EE_Event_List_Query($arrParams);

$all_posts = array();
$all_posts = array_merge($all_posts, $new->posts);

$postCount=0;
foreach ( $all_posts as $post ) : setup_postdata( $post );?>
<!– data im returning via ajax –>
<?php
wp_reset_query();
wp_reset_postdata();
endforeach; ?>

If I were doing this with the WordPress query I would query like this:

$arrParams = array(
‘post_type’ => array(‘doctor’),
‘paged’ => $pageID,
‘posts_per_page’ => ‘5’,
‘orderby’ => array( ‘menu_order’ => ‘ASC’ ),
‘suppress_filters’ => $suppressFilters
);

with the $pageId being returned on submit of the “load more” button to get the continuing data.

Any ideas on how to get the equivalent of the ‘paged’ parameter in the Event Espresso query?


Josh

  • Support Staff

December 19, 2016 at 1:08 pm

I can suggest using a normal WP query. You can order the normal WP Query by adding a join on the esp_datetime table, then set the order on the posts_order filter.


fjorgeDigital

December 19, 2016 at 3:06 pm

Do you have any code examples of what that might look like?


Josh

  • Support Staff

December 19, 2016 at 3:20 pm

https://gist.github.com/joshfeck/103efd299ce615188e978293a1254eeb


fjorgeDigital

December 19, 2016 at 4:20 pm

Okay – I tried adding that code to my functions.php as well as the individual template without any luck on getting them to order correctly.

I updated my query to use the WP query:
$arrParams = array(
‘post_type’ => array(‘espresso_events’),
‘paged’ => $pageID,
‘posts_per_page’ => ‘2’,
‘suppress_filters’ => false,
);

am I supposed to set the ‘orderby’ parameter to something? Still not getting the events loading in order of start date…


Josh

  • Support Staff

December 19, 2016 at 4:54 pm

No you will not need to set the orderly parameter to something, but you may need to adjust the example code’s conditionals to make sure the filters run on your query. Also note that the above linked example code in of itself does nothing because the my_event_list_query_template_function() isn’t called or attached to an action.

The support post ‘Load More Button Via Ajax and Custom Event Espresso Query’ 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.

Support forum for Event Espresso 3 and Event Espresso 4.
Documentation for EE3 and EE4
Documentation for Event Espresso 3

Documentation for Event Espresso 4

Status: closed

Updated by  Josh 2 years, 11 months ago ago

Topic Tags

Notifications

This topic is: not resolved
Do NOT follow this link or you will be banned from the site!