0

Below code is what i found from a search in daniweb forum. (Link)

Suppose i have a taxonomy called Color and terms are Blue, Green, Red, Yellow, White. I want when i select Blue, Green and Red and click submit button, i want to get ALL posts those have Blue OR Green OR Red (OR etc.) taxonomy term on the search results page.

Since the code below is just echoes "Insert Query - Blue, Insert Query - Red ...", is there any way to convert this into a code that in which i can get posts?

<?php
if(isset($_POST['clickhere'])) {
	$selected_values = $_POST['color'];
	foreach($selected_values as $key=>$value) {
                // Insert query comes here.
		echo "Insert Query - ".$value."<br />";
	}
	
	$select_blue = (in_array('1',$selected_values)) ? "selected" : "";
	$select_green = (in_array('2',$selected_values)) ? "selected" : "";
	$select_red = (in_array('3',$selected_values)) ? "selected" : "";
	$select_yellow = (in_array('4',$selected_values)) ? "selected" : "";
	$select_white = (in_array('5',$selected_values)) ? "selected" : "";
}
?>

<form name='testform' action='sometest.php' method='post'>
<select name='color[]' style="border:0px;" size=6 multiple>
<option value='' selected>Select Item</option>
<option value='1' <?php echo $select_blue;?> >Blue</option>
<option value='2'<?php echo $select_green;?> >Green</option>
<option value='3'<?php echo $select_red;?> >Red</option>
<option value='4'<?php echo $select_yellow;?> >Yellow</option>
<option value='5'<?php echo $select_white;?> >White</option>
</select>
<br /><br />
<input type='submit' name='clickhere' value='Click Here' />
</form>
3
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by ko ko
0

As far as I understand the question, you want to build up something like this:

SELECT * FROM `posts` WHERE `color` = 'blue' OR ....
0

I guess so. Thanks for the clue. But any further information?

0

Well, is it correct that you want to select rows from a database? If so, what did you try to build up this query? It also depends on what you want to do if no color has been selected. Make sure you don't end up with something like SELECT * FROM `posts` WHERE . As for databases as a whole, there's a nice tutorial on that there: http://devzone.zend.com/node/view/id/641

0

Okay, well, I didn't notice the fact that you're using Wordpress. Anyway, what are those colors for the posts? Tags? If so, you need something like this (but I think you don't want those numbers, but their names?):

query_posts('tag=' . implode('+', $selected_values));
0

It may sound like you need to involve the WP framework and their functions indeed. I've not seen if there is custom function working on the WP framework. Even if you can do, it is hard to compatible with WP and will cause may bugs.
Better way, see the WP function references and you should find the solution there. WP show all function references on their official website.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.