我想通过单击功能获得ajax帖子。
Jquery
$(".get-posts").click(function(){
$.ajax({
type: \'POST\',
url: \'<?php echo admin_url(\'admin-ajax.php\');?>\',
data: { action : \'get_ajax_posts\' },
success: function(){
// ???
}
});
});
Php
function get_ajax_posts() {
// Query Arguments
$args = array(
\'post_type\' => array(\'products\'),
\'post_status\' => array(\'publish\'),
\'posts_per_page\' => 40,
\'nopaging\' => true,
\'order\' => \'DESC\',
\'orderby\' => \'date\',
\'cat\' => 1,
);
// The Query
$ajaxposts = new WP_Query( $args );
// The Loop
if ( $ajaxposts->have_posts() ) {
while ( $ajaxposts->have_posts() ) {
$ajaxposts->the_post();
get_template_part(\'products\');
}
} else {
get_template_part(\'none\');
}
/* Restore original Post Data */
wp_reset_postdata();
}
add_action(\'wp_ajax_get_ajax_posts\', \'get_ajax_posts\');
add_action(\'wp_ajax_get_ajax_posts\', \'get_ajax_posts\');
我在这里被封锁了。