我的 ajax 文件在复选框中获取 term_id
$(document).ready(function() {
// Checkboxes click function
$('input[type="checkbox"]').on('click',function(){
var arr=[];
jQuery("input:checked").each(function(){
arr.push($(this).val());
});
// alert(arr);
jQuery.get("<?= bloginfo('template_directory'); ?>/template_classifiedstheme/productBySubCategory.php", { termId: $(this).val()},function(data){
// alert(data);
jQuery("#result").show();
jQuery("#result").html(data);
});
// Here we check which boxes in the same group have been selected
// Get the current group from the class
var group = $(this).attr("class");
var checked = [];
// Loop through the checked checkboxes in the same group
// and add their values to an array
$('input[type="checkbox"].' + group + ':checked').each(function(){
checked.push($(this).val());
});
//refreshData(checked, group);
});
// function refreshData($values, $group){
// alert("You've requested: " + $values + " from the group " + $group);
// }
});
在 post 值中获取 term_id 的我的 php 代码
foreach ($childCatID as $kid)
{
$childCatName = $wpdb->get_row("SELECT name,slug, term_id FROM $wpdb->terms WHERE term_id=$kid");
echo '<li><label class="lab_brand">
<span id="sp_brand">
<input type="checkbox" rel="brand" id="input_chk" value="'.$childCatName->term_id.'" onclick="getValue(this.id)" />
</span>
<a href="'.get_term_link($childCatName->slug, 'category').'">'.$childCatName->name.'</a>
</label>
</li>';
}
echo'</ul>
</div>';
通过此查询获取术语 ID 的我的 ajax 文件
$subcategory_id=$_GET['termId'];
$querystr = "SELECT *
FROM wp_terms
INNER JOIN wp_term_taxonomy ON wp_terms.term_id = wp_term_taxonomy.term_id
INNER JOIN wp_term_relationships wpr ON wpr.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id
INNER JOIN wp_posts p ON p.ID = wpr.object_id
WHERE taxonomy = 'category'
AND p.post_type = 'post'
AND p.post_status = 'publish'
AND wp_terms.term_id = $subcategory_id
但我们只能找到一个 term_id
当我选中多个复选框时,termId 中只有一个值