| Conditions | 3 |
| Paths | 2 |
| Total Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 23 | function spurs_loadmore_ajax_handler(){ |
||
| 24 | |||
| 25 | // prepare our arguments for the query |
||
| 26 | $args = json_decode( stripslashes( $_POST['query'] ), true ); |
||
| 27 | $args['paged'] = $_POST['page'] + 1; // we need next page to be loaded |
||
| 28 | $args['post_status'] = 'publish'; |
||
| 29 | |||
| 30 | // it is always better to use WP_Query but not here |
||
| 31 | query_posts( $args ); |
||
| 32 | |||
| 33 | if( have_posts() ) : |
||
| 34 | |||
| 35 | // run the loop |
||
| 36 | while( have_posts() ): the_post(); |
||
|
|
|||
| 37 | |||
| 38 | // look into your theme code how the posts are inserted, but you can use your own HTML of course |
||
| 39 | // do you remember? - my example is adapted for Twenty Seventeen theme |
||
| 40 | get_template_part( 'templates/loop/content', get_post_format() ); |
||
| 41 | // for the test purposes comment the line above and uncomment the below one |
||
| 42 | // the_title(); |
||
| 43 | |||
| 44 | |||
| 45 | endwhile; |
||
| 46 | |||
| 47 | endif; |
||
| 48 | die; // here we exit the script and even no wp_reset_query() required! |
||
| 49 | } |
||
| 50 | |||
| 54 | add_action('wp_ajax_nopriv_loadmore', 'spurs_loadmore_ajax_handler'); // wp_ajax_nopriv_{action} |