此代码目前无效。我正在使用wordpress并尝试根据所选的下拉列表显示内容。更具体地说,内容是基于分类法的不同循环。
<form method="post" action="">
<select name="only_criteria" onchange="submit();">
<option selected="selected">Please Choose</option>
<option value="one">One</option>
<option value="two">Two</option>
<option value="three">Three</option>
</select>
</form>
<div class="archive-wrap">
<div class="carousel">
<?php
if(isset($_POST['only_criteria']) && $_POST['only_criteria'] == '') {
$loop = new WP_Query( array(
'post_type' => 'my_custom_post_type',
'posts_per_page' => -1,
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'my_taxonomy',
'terms' => array( 'tax_one','tax_two','tax_three'),
),
),
) );
} else if(isset($_POST['only_criteria']) && $_POST['only_criteria'] == 'one') {
$loop = new WP_Query( array(
'post_type' => 'my_custom_post_type',
'posts_per_page' => -1,
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'my_taxonomy',
'terms' => array( 'tax_one'),
),
),
) );
} else if(isset($_POST['only_criteria']) && $_POST['only_criteria'] == 'two') {
$loop = new WP_Query( array(
'post_type' => 'my_custom_post_type',
'posts_per_page' => -1,
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'my_taxonomy',
'terms' => array( 'tax_two'),
),
),
) );
} else if(isset($_POST['only_criteria']) && $_POST['only_criteria'] == 'three') {
$loop = new WP_Query( array(
'post_type' => 'my_custom_post_type',
'posts_per_page' => -1,
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'my_taxonomy',
'terms' => array('tax_three'),
),
),
) );
}
?>
我通过将每个循环放在一个标签中来完成与标签类似的事情。我希望使用该表单,因为我认为它会减少加载时间并提高效率。