您可以轻松地将任何想要的变量添加到AJAX调用中。
使用jQuery可以设置如下AJAX操作:
jQuery.post(
\'your-url-to-admin-ajax.php\',
{
action: \'your_called_function\',
argument: \'year\' or \'category\',
some_other_var: \'some value\'
},
function( response ) {
if(response) {
} else {
}
}
);
然后在你的函数中。php添加以下内容:
add_action( \'wp_ajax_nopriv_your_called_function\', \'your_called_function\' );
add_action( \'wp_ajax_your_called_function\', \'your_called_function\' );
function your_called_function() {
$argument = $_POST[\'argument\'];
$otherVar = $_POST[\'some_other_var\'];
// now you can do the loop with your argument
// important to add exit(), or it won\'t work
exit();
}
详情如下:
http://www.makeuseof.com/tag/tutorial-ajax-wordpress/