Skip to content

Instantly share code, notes, and snippets.

@omartdev
Created March 27, 2018 12:06
Show Gist options
  • Save omartdev/0244180a95f54d9d1a291c1e598628e2 to your computer and use it in GitHub Desktop.
Save omartdev/0244180a95f54d9d1a291c1e598628e2 to your computer and use it in GitHub Desktop.
// load more post function.php
add_action('wp_ajax_load_posts_by_ajax', 'load_posts_by_ajax_callback');
add_action('wp_ajax_nopriv_load_posts_by_ajax', 'load_posts_by_ajax_callback');
function load_posts_by_ajax_callback() {
check_ajax_referer('load_more_posts', 'security');
$paged = $_POST['page'];
$newsletter_lists = get_posts(array('post_type'=>'newsletter','posts_per_page' => 8,'paged' => $paged,));
if ( $newsletter_lists ) {
foreach ( $newsletter_lists as $newsletter_list ) :
setup_postdata( $newsletter_list );
$thumb_url = get_thumbanil_url($newsletter_list,'full'); ?>
<div class="col-md-3">
<div class="news_item">
<figure>
<a href="#"><img class="img-fluid" src="<?php echo $thumb_url; ?>" alt=""></a>
<figcaption>
<a href="#">
<h4 class="h4"><?php echo $newsletter_list->post_title; ?></h4>
<p>Issued on <?php echo get_the_date('M Y',$newsletter_list->ID); ?></p>
</a>
</figcaption>
</figure>
</div>
<!-- /.news_item -->
</div>
<!-- /.col-md-3 -->
<?php
endforeach;
wp_reset_postdata();
}
else{
echo $er = "No more posts to load";
}
wp_die();
}
_______________________________
<div class="row m-t-70">
<?php $newsletter_lists = get_posts(array('post_type'=>'newsletter','posts_per_page' => 8));
$i = 1;
if ( $newsletter_lists ) {
foreach ( $newsletter_lists as $newsletter_list ) :
// print_r(post);
setup_postdata( $newsletter_list );
$thumb_url = get_thumbanil_url($newsletter_list,'full'); ?>
<div class="col-md-3">
<div class="news_item">
<figure>
<a href="#"><img class="img-fluid" src="<?php echo $thumb_url; ?>" alt=""></a>
<figcaption>
<a href="#">
<h4 class="h4"><?php echo $newsletter_list->post_title; ?> </h4>
<p>Issued on <?php echo get_the_date('M Y'); ?></p>
</a>
</figcaption>
</figure>
</div>
<!-- /.news_item -->
</div>
<!-- /.col-md-3 -->
<?php
$i++;
endforeach;
wp_reset_postdata();
}
?>
<div class="center">
<!-- <a href="#" class="fps-btn li-pink-btn">see More</a> -->
<div class="loadmore fps-btn li-pink-btn">See More</div>
<div class="loading_more"></div>
</div>
</div>
<!-- /.row -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment