的functions.php
add_action( 'get_wp_ajax_publications', 'get_publications' );
add_action( 'get_wp_ajax_nopriv_publications', 'get_publications' );
function get_publications() {
if ( isset($_REQUEST) ) {
$args = array( 'post_type' => 'publications', 'posts_per_page' => 2, 'offset' => 2 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
the_title();
echo '<div class="entry-content">';
the_content();
echo '</div>';
endwhile;
}
die();
}
myloadmore.js
$(document).ready(function(){
var offset_value = 0;
$('#loadmore').click(function() {
$.ajax({
url: ajaxurl,
data: {
'action' : 'get_publications',
'offset' : offset_value
},
success:function(data) {
$('#posts').html(data);
}
});
console.log('loadmore clicked');
offset_value +=2;
return false;
});
});
答案 0 :(得分:0)
解决了!不得不改变我的钩子的名字
add_action( 'get_wp_ajax_publications', 'get_publications' );
add_action( 'get_wp_ajax_nopriv_publications', 'get_publications' );
应该是
add_action( 'wp_ajax_publications', 'get_publications' );
add_action( 'wp_ajax_nopriv_publications', 'get_publications' );
从我的wp ajax电话前面放下了get_!非常感谢你的帮助@rjustin