gpt4 book ai didi

php - 我们如何在此查询中添加超过 $subcategory_id 的内容

转载 作者:行者123 更新时间:2023-11-30 01:32:20 25 4
gpt4 key购买 nike

我的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);
// }

});

我的用于在帖子值中获取 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>';

我的ajax文件,用于通过此查询获取术语ID

$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 中只能获取一个值

最佳答案

我将在这里进行长镜头假设您问的是如何添加多个 $subcategory_id。

在这种情况下,我会将您的表单元素设置为 name='termId[]',以便您可以拥有一个值数组。

然后将查询更改为结尾(我假设您会用引号将其引起来:

' AND wp_terms.term_id IN ( '.implode(",",$subcategory_id) . ' )';

否则,您可以在查询中添加多个 AND 子句。即

AND wp_terms.term_id = '$variable'

关于php - 我们如何在此查询中添加超过 $subcategory_id 的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17319379/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com