我..。
1-多个HTML标签,每个标签都有不同的id属性。
<a href="#" name="term_id" class="cat_image" id="1">
<a href="#" name="term_id" class="cat_image" id="2">
<a href="#" name="term_id" class="cat_image" id="3">
<a href="#" name="term_id" class="cat_image" id="4">
2- WordPress函数,获取id并将其作为id分配给tax_query数组-> terms
$args = array(
'numberposts' => -1,
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => ** the id goes here **,
'operator' => 'IN'
)),
'post_type' => 'product',
'orderby' => 'author',
'order' => 'ASC',
'post_status' => 'publish'
);
$cat_posts = get_posts($args);
当用户单击一个标记时,我想将这个被单击的id分配给tax_query数组...
然后我想使用ajax显示该类别的帖子。
到目前为止,我在这里
jQuery('.cat_image').click(function(){
jQuery.ajax({
url:"/wp-admin/admin-ajax.php",
data:jQuery(this).attr("id"),
type:"POST", // POST
beforeSend:function(xhr){
console.log('Processing...');
},
success:function(data){
console.log('success');
}
})//ajax ends here;
return false;
});
发布于 2019-10-07 19:59:09
将您的数据参数更改为:
data: { term_id: jQuery(this).attr("id") }
然后,在PHP文件中,您可以使用$_POST['term_id']
来检索ID。
https://stackoverflow.com/questions/58258953
复制相似问题