Support

Home Forums Event Espresso Premium Problem In Load More Event Reply To: Problem In Load More Event

Reply To: Problem In Load More Event

Author Replies
bizcat # Posted on May 9, 2018 at 9:48 pm

Hi Josh,

Thanks for quick response.

Please check below reference link.
I have taken code from that (your example-query.php) to create custom page template but when I try to create ajax load more pagination that time I need to pass “paged” parameter and that was not working as per reference code.

( Just change $wp_query = new EE_Event_List_Query( $atts ); instead of your $wp_query = new EventEspresso\core\domain\services\wp_queries\EventListQuery( $atts ); )
Reference : https://gist.github.com/joshfeck/e3c9540cd4ccc734e755

Ajax Load More my referred link: https://stackoverflow.com/questions/31587210/load-more-posts-ajax-button-in-wordpress

As per above ajax reference link we need to pass data to “paged” parameter to get next post so I have try to implement this in your your code but it don’t work.

can you please help me to implement load more ajax query?

// ===== ==== Page template code ===== ====
I used your example-query.php code.

// ============ Load more ajax function ======== ======
<?php
function more_post_ajax(){

$ppp = (isset($_POST["ppp"])) ? $_POST["ppp"] : 3;
$page = (isset($_POST['pageNumber'])) ? $_POST['pageNumber'] : 0;

header("Content-Type: text/html");

$atts = array(
'title' => NULL,
'limit' => $ppp,
'paged' => $page,
'css_class' => NULL,
'show_expired' => FALSE,
'month' => NULL,
'category_slug' => NULL,
'order_by' => 'start_date',
'sort' => 'DSC',
);
$loop = new EE_Event_List_Query( $atts );

$out = '';

if ($loop -> have_posts()) : while ($loop -> have_posts()) : $loop -> the_post();
$out .= '<div class="small-12 large-4 columns">
<h1>'.get_the_title().'</h1>
<p>'.get_the_content().'</p>
</div>';

endwhile;
endif;
wp_reset_postdata();
die($out);
}

add_action('wp_ajax_nopriv_more_post_ajax', 'more_post_ajax');
add_action('wp_ajax_more_post_ajax', 'more_post_ajax');

// ===== ==== Ajax code in javascript file ===== ====
var ppp = 3; // Post per page
var cat = 8;
var pageNumber = 1;

function load_posts(){
pageNumber++;
var str = '&cat=' + cat + '&pageNumber=' + pageNumber + '&ppp=' + ppp + '&action=more_post_ajax';
$.ajax({
type: "POST",
dataType: "html",
url: ajaxurl, // Define ajax url in file
data: str,
success: function(data){
var $data = $(data);
if($data.length){
$("#ajax-posts").append($data);
$("#more_posts").attr("disabled",false);
} else{
$("#more_posts").attr("disabled",true);
}
},
error : function(jqXHR, textStatus, errorThrown) {
$loader.html(jqXHR + " :: " + textStatus + " :: " + errorThrown);
}

});
return false;
}

$("#more_posts").on("click",function(){ // When btn is pressed.
$("#more_posts").attr("disabled",true); // Disable the button, temp.
load_posts();
});

If I used above all code with post or Custom post type then it will work fine but with Event Espresso I didn’t found why it is not working.

Please help me to implement Load more functionality into Event Espresso.

Thanks,
Pankaj

Do NOT follow this link or you will be banned from the site!