我对早期的代码做了一些调整,第一个过滤器目前运行良好,我对其余部分有点困惑,有什么建议吗?你能帮我把这个带到有效的地方吗。
<!-- last edit started by dev -->
<script type="text/javascript">
function onchangedestination(str)
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
document.getElementById("data").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","http://example.com/ajax?opt="+str, true);
xmlhttp.send();
}
</script>
<select class="tourdestination" name="tourdestination" id="tourdestination" onchange="onchangedestination(this.value);">
<option value="" selected="selected">All Destinations</option>
<?php
foreach( get_categories(\'taxonomy=tour_destination&post_type=tour&hide_empty=false\') as $cat ) :
if( !$cat->parent ) // if cat info not has parents
{
echo \'<option value="\' . $cat->term_id . \'" >\' . $cat->name . \'</option>\';
category_tree( $cat->term_id );
}
endforeach;
wp_reset_query();
function category_tree( $cat ) { // passing ids of category
$args = array(\'category__in\' => array( $cat ));
$next = get_categories(\'taxonomy=tour_destination&hide_empty=false&parent=\' . $cat);
if( $next ) :
foreach( $next as $cat ) :
echo \'<option value="\' . $cat->term_id . \'" > \' . $cat->name.\'</option>\';
category_tree( $cat->term_id );
endforeach;
endif;
}
?>
</select>
<div id="data"></div>
文件测试。php
<?php
$opt = $_GET[\'opt\'];
$pages = get_posts(array(
\'post_type\' => \'tour\',
\'numberposts\' => -1,
\'tax_query\' => array(
array
(
\'taxonomy\' => \'tour_destination\',
\'field\' => \'id\',
\'terms\' => $opt, // above code will return the id here.
\'include_children\' => false
)
)
));
$post_id =array();
//$tour_type = array();
$categories = array();
foreach ($pages as $page)
{
$post_id[] = $page->ID;
}
?>
<?php //echo $count = count($post_id) . \'Total Posts <br>\'; ?>
<?php foreach($post_id as $p_ID): ?>
<?php $tours = wp_get_post_terms($p_ID, \'tour_type\', array("fields" => "all")); ?>
<?php $month_travels = wp_get_post_terms($p_ID, \'month_travel\', array("fields" => "all")); ?>
<?php $year_travels = wp_get_post_terms($p_ID, \'year_travel\', array("fields" => "all")); ?>
<?php $led_bys = wp_get_post_terms($p_ID, \'led_by\', array("fields" => "all")); ?>
<!-- fetching tour data -->
<?php foreach($tours as $tour): ?>
<?php $array_tour[\'id\'] = $tour->term_id; ?>
<?php $array_tour[\'name\'] = $tour->name; ?>
<?php endforeach; ?>
<!-- fetching month data -->
<?php foreach($month_travels as $month_travel): ?>
<?php $array_month[\'id\'] = $month_travel->term_id; ?>
<?php $array_month[\'name\'] = $month_travel->name; ?>
<?php endforeach; ?>
<!-- fetching year data -->
<?php foreach($year_travels as $year_travel): ?>
<?php $array_year[\'id\'] = $year_travel->term_id; ?>
<?php $array_year[\'name\'] = $year_travel->name; ?>
<?php endforeach; ?>
<!-- fetching led by data -->
<?php foreach($led_bys as $led_by): ?>
<?php $array_led_by[\'id\'] = $led_by->term_id; ?>
<?php $array_led_by[\'name\'] = $led_by->name; ?>
<?php endforeach; ?>
<?php $categories_tour[] = array(\'id\' => $array_tour[\'id\'], \'name\' => $array_tour[\'name\']); ?>
<?php $categories_month[] = array(\'id\' => $array_month[\'id\'], \'name\' => $array_month[\'name\']); ?>
<?php $categories_year[] = array(\'id\' => $array_year[\'id\'], \'name\' => $array_year[\'name\']); ?>
<?php $categories_led_by[] = array(\'id\' => $array_led_by[\'id\'], \'name\' => $array_led_by[\'name\']); ?>
<?php endforeach; ?>
<!--Removing duplicates-->
<?php $input_tour = array_map("unserialize", array_unique(array_map("serialize", $categories_tour))); ?>
<?php $input_month = array_map("unserialize", array_unique(array_map("serialize", $categories_month))); ?>
<?php $input_year = array_map("unserialize", array_unique(array_map("serialize", $categories_year))); ?>
<?php $input_led_by = array_map("unserialize", array_unique(array_map("serialize", $categories_led_by))); ?>
<select id="type">
<?php foreach($input_tour as $tour_category): ?>
<?php echo "<option id=" . $tour_category[\'id\'] .">" . $tour_category[\'name\'] . "</option>"; ?>
<?php endforeach; ?>
</select>
<select id="month">
<?php foreach($input_month as $month_category): ?>
<?php echo "<option id=" . $month_category[\'id\'] .">" . $month_category[\'name\'] . "</option>"; ?>
<?php endforeach; ?>
</select>
<select id="year">
<?php foreach($input_year as $year_category): ?>
<?php echo "<option id=" . $year_category[\'id\'] .">" . $year_category[\'name\'] . "</option>"; ?>
<?php endforeach; ?>
</select>
<select id="led_by">
<?php foreach($input_led_by as $led_by_category): ?>
<?php echo "<option id=" . $led_by_category[\'id\'] .">" . $led_by_category[\'name\'] . "</option>"; ?>
<?php endforeach; ?>
</select>
如果我在任何地方出错,请建议我。。。,谢谢