我正在尝试创建自定义分类法。php页面,我的用户可以在该页面中优化搜索。我尝试创建一种循环,如:
<?php
if(!empty($_GET[\'ending\']))
{
$ends = array(
\'key\' => \'ending\',
\'value\' => (current_time(\'timestamp\', 0) + 3600*24*$_GET[\'ending\']),
//\'type\' => \'numeric\',
\'compare\' => \'<\'
);
}
if(!empty($_GET[\'budgets\']))
{
$budgets = array(
\'key\' => \'budgets\',
\'value\' => $_GET[\'budgets\'],
//\'type\' => \'numeric\',
\'compare\' => \'=\'
);
}
$taxonomy = get_query_var(\'taxonomy\');
$post_per_page = 10;
$args = array(
\'post_type\' => \'project\',
\'order\' => \'DESC\',
\'orderby\' => \'date\',
\'posts_per_page\' => $post_per_page,
\'paged\' => 1,
\'meta_query\' => array($closed, $ends, $budgets ),
\'s\'=> GET(\'keyword\'),
\'post_status\' =>array(\'publish\'),
\'tax_query\' => array(
array(
\'taxonomy\' => $taxonomy,
\'field\' => \'slug\',
\'terms\' => $term->slug
)
)
);
query_posts($args);
if ( have_posts() ): while ( have_posts() ) : the_post();
KleeiaDev_get_post();
endwhile;
if(function_exists(\'wp_pagenavi\')):
wp_pagenavi(); endif;
wp_reset_postdata();
else:
echo __(\'No projects posted here yet.\',"KleeiaDev");
endif;
wp_reset_query();
?>
应该过滤查询的我的元素有
$ends
,
$budgets
和
\'s\'=> GET(\'keyword\')
它们与我的侧型相连,如下所示。
<form method="get" action="<?php echo $lnk ?>">
<div class="col-sm-12">
<input type="text" placeholder="<?php _e(\'Type something here\',\'KleeiaDev\') ?>" value="<?php echo stripslashes($_GET[\'keyword\']) ?>" name="keyword" size="30" class="form-control" />
</div>
<div class="col-sm-6 col-md-12">
<?php echo ProjecTheme_get_budgets_dropdown($_GET[\'budgets\'], \'form-control top-15\' , 1); ?>
</div>
<div class="col-sm-6 col-md-12">
<select name="ending" class="form-control top-15">
<option value=""><?php _e(\'Ending in\',\'KleeiaDev\') ?></option>
<option value="1" <?php echo ($_GET[\'ending\'] == 1 ? \'selected="selected"\' : \'\') ?>><?php _e(\'1 day\',\'KleeiaDev\') ?></option>
<option value="7" <?php echo ($_GET[\'ending\'] == 7 ? \'selected="selected"\' : \'\') ?>><?php _e(\'7 days\',\'KleeiaDev\') ?></option>
<option value="30" <?php echo ($_GET[\'ending\'] == 30 ? \'selected="selected"\' : \'\') ?>><?php _e(\'30 days\',\'KleeiaDev\') ?></option>
<option value="180" <?php echo ($_GET[\'ending\'] == 180 ? \'selected="selected"\' : \'\') ?>><?php _e(\'6 Months\',\'KleeiaDev\') ?></option>
</select>
</div>
<div class="col-sm-6 col-md-12">
<input type="submit" name="apply_filters" class="submit_green top-15 full_width text-center" value="<?php _e(\'Refine search\',\'KleeiaDev\') ?>" />
</div>
</form>
我的目标是在两个固定条件下优化结果:
$taxonomy && $closed
[在$分类法中所有$关闭的帖子]+最终[$预算和关键字和$结束]。当我提交时,表单会生成一个url,如
mydomain.com/?keyword=hello&budgets=&ending=7&apply_filters=Refine+search
但我总是在没有应用过滤器的情况下得到该分类法的所有结果。我不知道如何继续,因为我不太擅长提问。我读过
query_posts
抄本部分没有进一步说明。