0

チェックボックスでterm_idを取得する私のajaxファイル

$(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を取得するためのMY 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 を取得するための MY 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 は 1 つしか見つかりません

複数のチェックボックスをオンにすると、termId に値が 1 つだけ取得されます

4

2 に答える 2