[英]Wordpress query_posts from GET submission
I'm trying - and failing miserably - to construct a new query_posts
query using the values from a form submitted using Wordpress' wp_dropdown_categories
. 我正在尝试-惨遭失败-使用Wordpress的wp_dropdown_categories
提交的表单中的值构造一个新的query_posts
查询。
Here's the form: 形式如下:
<form action="<?php bloginfo('url')/filter.php" method="GET">
<?php wp_dropdown_categories('child_of=1&name=colour'); ?>
<?php wp_dropdown_categories('child_of=2&name=type'); ?>
<input type="submit" name="submit" value="view" />
</form>
Which renders the following HTML (simplified a little to save space) 呈现以下HTML(简化一些以节省空间)
<form action="http://localhost:8888/project/wp-content/themes/project/filter.php" method="GET">
<select name='colour' id='colour' class='postform' >
<option value="3">Red</option>
<option value="4">Blue</option>
<option value="5">Blue</option>
</select>
<select name='type' id='colour' class='postform' >
<option value="6">Small</option>
<option value="7">Medium</option>
<option value="8">Large</option>
</select>
<input type="submit" name="submit" value="view" />
</form>
And here's the filter.php
file contents 这是filter.php
文件的内容
<?php
$args = array(
'category__in' => array(HELP HERE);
query_posts( $args );
// The Loop
while ( have_posts() ) : the_post();
echo '<li>';the_title();
echo '</li>';
endwhile;
// Reset Query
wp_reset_query();
?>
The most important factor here is that this needs to be flexible; 这里最重要的因素是这需要灵活。 in other words if only one of the selects is used, the query should still work. 换句话说,如果仅使用选择项之一,则查询仍将起作用。
I think I'm most of the way there, it's just construction the array for the category__in => array()
from the values of any of the selected options that's doing my head in. 我想我大部分都在那儿,它只是根据我所参与的任何选定选项的值构造category__in => array()
。
Thanks for any help! 谢谢你的帮助!
This seems to work for now. 这似乎暂时有效。
<?php
$args = array(
'category__in' => array($_GET['colour'], $_GET['type'])
);
query_posts( $args );
// The Loop
while ( have_posts() ) : the_post();
echo '<li>';the_title();
echo '</li>';
endwhile;
// Reset Query
wp_reset_query();
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.