1. Copy the below code and paste into footer.php or any js file.
jQuery('.show-more-posts-btn').on('click',function(){
var data = {
'action': 'view_post_filters',
'pageno': 1
};
jQuery.get(ajaxurl, data, function(response) {
console.log(response);
});
})
var data = {
'action': 'view_post_filters',
'pageno': 1
};
jQuery.get(ajaxurl, data, function(response) {
console.log(response);
});
})
2. Copy and paste the below code to get all posts-
//defined action
add_action('wp_ajax_view_post_filters', "view_more_post_handler");
add_action('wp_ajax_nopriv_view_post_filters', "view_more_post_handler");
function view_more_post_handler()
{
$results = get_posts(array('posts_per_page'=> 5, 'paged' => $_GET['pageno'], 'orderby' => 'date', 'order' => 'DESC'));
$html='';
if( $results )
{
foreach( $related as $post ) {
setup_postdata($post);
$html.= '<li>
<img src="'.get_the_post_thumbnail_url($post->ID).'" class="flips_related_featured">
<p>'. get_the_excerpt($post->ID).' </p> </li>';
}
}
else{
$html.= "<p> <strong> Data not found !</strong> </p>";
}
echo $html; exit;
}
add_action('wp_ajax_view_post_filters', "view_more_post_handler");
add_action('wp_ajax_nopriv_view_post_filters', "view_more_post_handler");
function view_more_post_handler()
{
$results = get_posts(array('posts_per_page'=> 5, 'paged' => $_GET['pageno'], 'orderby' => 'date', 'order' => 'DESC'));
$html='';
if( $results )
{
foreach( $related as $post ) {
setup_postdata($post);
$html.= '<li>
<img src="'.get_the_post_thumbnail_url($post->ID).'" class="flips_related_featured">
<p>'. get_the_excerpt($post->ID).' </p> </li>';
}
}
else{
$html.= "<p> <strong> Data not found !</strong> </p>";
}
echo $html; exit;
}