Advertisement
delvinkrasniqi

functions

Feb 5th, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. function blog_scripts() {
  2. // Register the script
  3. wp_register_script( 'custom-script', get_stylesheet_directory_uri(). '/js/custom.js', array('jquery'), false, true );
  4.  
  5. // Localize the script with new data
  6. $script_data_array = array(
  7. 'ajaxurl' => admin_url( 'admin-ajax.php' ),
  8. 'security' => wp_create_nonce( 'load_more_posts' ),
  9. );
  10. wp_localize_script( 'custom-script', 'blog', $script_data_array );
  11.  
  12. // Enqueued script with localized data.
  13. wp_enqueue_script( 'custom-script' );
  14. }
  15. add_action( 'wp_enqueue_scripts', 'blog_scripts' );
  16.  
  17.  
  18. function load_posts_by_ajax_callback() {
  19. check_ajax_referer('load_more_posts', 'security');
  20. $paged = $_POST['page'];
  21. $args = array(
  22. 'post_type' => 'reviews',
  23. 'post_status' => 'publish',
  24. 'posts_per_page' => '4',
  25. 'order'=>'ASC',
  26. 'paged' => $paged,
  27. );
  28. $my_posts = new WP_Query( $args );
  29. ?>
  30.  
  31. <?php if ( $my_posts->have_posts() ) : ?>
  32. <?php while ( $my_posts->have_posts() ) : $my_posts->the_post(); ?>
  33. <div class="col-12 reviews">
  34. <div class="firstrw">
  35. <div class="foto-wrap">
  36. <?php the_post_thumbnail();?>
  37. <div class="firstrw_content">
  38. <h1><?php the_title();?></h1>
  39. <p id="data"><?php echo get_the_date( 'd-m-Y' ); ?></p>
  40. </div>
  41. </div>
  42. <div class="star-rating">
  43. <p><?php the_field('stars');?></p>
  44. </div>
  45. </div>
  46.  
  47. <?php the_content();?>
  48. <hr>
  49. </div>
  50. <?php endwhile; ?>
  51. <?php
  52. endif;
  53.  
  54. wp_die();
  55. }
  56. add_action('wp_ajax_load_posts_by_ajax', 'load_posts_by_ajax_callback');
  57. add_action('wp_ajax_nopriv_load_posts_by_ajax', 'load_posts_by_ajax_callback');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement