Advertisement
martawijaya

load more ajax post

Sep 10th, 2019
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.51 KB | None | 0 0
  1. function more_post_ajax(){
  2.  
  3.     $ppp = (isset($_POST["ppp"])) ? $_POST["ppp"] : 9;
  4.     $page = (isset($_POST['pageNumber'])) ? $_POST['pageNumber'] : 0;
  5.  
  6.     header("Content-Type: text/html");
  7.  
  8.     $args = array(
  9.         'suppress_filters' => true,
  10.         'post_type' => 'post',
  11.         'posts_per_page' => $ppp,
  12.         'paged'    => $page,
  13.     );
  14.  
  15.     $loop = new WP_Query($args);
  16.  
  17.     $out = '';
  18.  
  19.     if ($loop -> have_posts()) :  while ($loop -> have_posts()) : $loop -> the_post();
  20.  
  21.          $thumb2 = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' );
  22.          $out .= '<div class="col-xl-4 col-lg-4 col-md-4 col-sm-12 col-xs-12 blog-item-wrap">
  23.              <a class="post-list-item" href="'.get_the_permalink().'">
  24.                  <div class="post-list-item-wrapper">
  25.                    <div class="item-post-thumbnail">
  26.                       <img class="lazyload" data-src="'.$thumb2[0]. '">
  27.                    </div>
  28.                    <div class="item-post-content">
  29.                        <h2>'.get_the_title().'</h2>
  30.                        <span class="post-date">'.get_the_time('j F Y').'</span>
  31.                        <p>'.wp_trim_words( get_field('introduce_text'), 15 ).'</p>
  32.                    </div>
  33.                  </div>
  34.               </a>
  35.          </div>';
  36.  
  37.     endwhile;
  38.     endif;
  39.     wp_reset_postdata();
  40.     die($out);
  41. }
  42.  
  43.  
  44. add_action('wp_ajax_nopriv_more_post_ajax', 'more_post_ajax');
  45.   add_action('wp_ajax_more_post_ajax', 'more_post_ajax');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement