`
<?php
$args = array(
'category_name'=>'work',
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => '3',
'paged' => 1,
);
$my_posts = new WP_Query( $args );
if ( $my_posts->have_posts() ) :
?>
//查询显示帖子 have_posts()):$ my_posts-> the_post()?>
<?php endif ?>`
$(document).on('click','.loadmore', function(){
var page = 2;
var ajaxurl = '<?php echo admin_url( 'admin-ajax.php' ); ?>';
$.ajax({
url: ajaxurl,
type :'post',
data :{
page : page,
action: 'load_posts_by_ajax'
},
error :function(response){
console.log(response);
},
success : function(response){
$('.my-posts').append(response);
page++;
}
});
});
我得到了重复的价值
<?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'];
$args = array(
'category_name'=>'work',
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => '3',
'paged' => $paged,
);
$my_posts = new WP_Query( $args );
if ( $my_posts->have_posts() ) : while($my_posts->have_posts() ) : $my_posts->the_post()
?>
<?php the_title() the_excerpt() endwhile; endif; wp_die();
}