这是我最终使用的完整代码,因为似乎没有办法在查询中引入“OR”作为关系。这只是检查查询字符串中出现的查询,然后将正确的参数应用于WP\\U查询。希望这一切都有意义!
<?php
$locationq = $_REQUEST["location"];
$monthq = $_REQUEST[\'month\'];
$yearq = $_REQUEST[\'year\'];
$searchq = $_REQUEST[\'keyword\'];
//list terms in a given taxonomy
$taxonomy = \'careerlocation\';
$tax_terms = get_terms($taxonomy);
echo \'<div class="careerbox locationpicker">\';
echo \'<select class="locationlinks">\';
echo \'<option value="" disabled="disabled" selected="selected">Select a region</option>\';
echo \'<option value="">View All</a></li>\';
foreach ($tax_terms as $tax_term) {
echo \'<option value="?location=\'.$tax_term->slug.\'">\' . $tax_term->name . \'</option>\'."\\n";
}
echo \'</select>\';
echo \'</div>\';
//list month and year of listed positions
echo \'<div class="careerbox datepicker">\';
echo \' <select class="datelinks">\';
echo \' <option value="" disabled="disabled" selected="selected">Date Posted</option>\';
$current_date = "";
$count_posts = wp_count_posts();
$nextpost = 0;
$published_posts = $count_posts->publish;
$myposts = get_posts(array(
\'post_type\' => \'career\',
\'posts_per_page\' => $published_posts
));
foreach($myposts as $post) :
$nextpost++;
setup_postdata($post);
$date = get_the_date("F Y");
if($current_date!=$date):
//echo \'<option value="">\'. $date .\'</option>\';
$dt = strtotime($date);
$month=date(\'m\',$dt);
$year=date(\'Y\',$dt);
echo \'<option value="?month=\'.$month.\'&year=\'.$year.\'">\'. $date .\'</option>\';
$current_date = $date;
endif;
endforeach;
wp_reset_postdata();
echo \' </select>\';
echo \'</div>\';
?>
</div>
<?php
//now run query filter on either date or location
if($locationq) {
$qu = \'tax_query\';
$typequery = array(
array(
\'taxonomy\' => \'careerlocation\',
\'terms\' => $locationq,
\'field\' => \'slug\',
\'operator\' => \'IN\',
\'include_children\' => false
)
);
} else if($monthq || $yearq) {
$qu = \'date_query\';
$typequery = array(
array(
\'year\' => intval($yearq),
\'month\' => intval($monthq),
\'compare\' => \'=\'
)
);
} else if($searchq) {
$qu = \'s\';
$typequery = $searchq;
}
$jobargs = array(
\'post_type\' => \'career\',
$qu => $typequery
);
$careersq = new WP_Query($jobargs);
?>