Wordpress: Multiple select values

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
adige
Forum Newbie
Posts: 4
Joined: Fri Apr 15, 2011 1:22 pm

Wordpress: Multiple select values

Post by adige »

Below code is what i found from a search in web.

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?

Thanks.

Code: Select all

<?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>
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Wordpress: Multiple select values

Post by Jade »

You can use the wordpress API to get the values from the database. There's also a function reference that you might find useful. Otherwise you'll need to write a query to go out and find/display the results yourself.
Post Reply