Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. function get_posts_for_pagination() {
  2. $html = '';
  3. $paged = ( $_GET['page'] ) ? $_GET['page'] : 1;
  4. $post_type = $_GET['posttype'];
  5.  
  6. if ( empty($post_type) ) {
  7. return '';
  8. }
  9.  
  10. if( filter_var( intval( $paged ), FILTER_VALIDATE_INT ) ) {
  11.  
  12. $args = array(
  13. 'post_type' => $post_type,
  14. 'paged' => $paged,
  15. 'posts_per_page' => 4,
  16. 'post_status' =>'publish'
  17. );
  18.  
  19. $loop = new WP_Query( $args );
  20.  
  21. $post_count = $loop->found_posts;
  22. $max_num_pages = $loop->max_num_pages;
  23.  
  24. if( $loop->have_posts() ) {
  25. while( $loop->have_posts() ) {
  26. $loop->the_post();
  27.  
  28. $html .= 'your output'
  29. }
  30. wp_reset_query();
  31. }
  32. }
  33.  
  34. echo $html;
  35. exit();
  36. }
  37.  
  38. add_action( 'wp_ajax_pagination', 'get_posts_for_pagination' );
  39. add_action( 'wp_ajax_nopriv_pagination', 'get_posts_for_pagination' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement