Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I can successfully query post results using query posts like so...

<?php

// The Query
query_posts("gdsr_sort=rating");

// The Loop
while ( have_posts() ) : the_post();
?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php 
endwhile;

// Reset Query
wp_reset_query();

?>

I was wondering if it's possible to make a dropdown menu where users can select different queries. So an example would a dropdown menu that says "Select Query" by deafult then when you click the dropdown menu it gives you different options like "Query 1", "Query 2", Query 3".. and when you click on one it loads the correct query for whatever query is set to number 1, 2, or 3.

I've done a lot of research and haven't found too much help regarding this issue. I don't know if I should set up an if / else statement connect that to the <select> input and then.. I don't know where to go from there.. or if that is even a proper way of doing it.

So, how would I make a dropdown menu that successfully loads different post queries? Any help would truly be appreciated. :)

share|improve this question
1  
You are talking about basic PHP. Look up "creating processing form PHP". –  s_ha_dum Jan 15 '13 at 1:51
    
@s_ha_dum Creating a dropdown that takes any page that a user is currently on and applies a query to it is basic php? really? I've searched a lot of different things on google to find a solution to this question and have yet to find an example or anything like that. I appreciate your comment, but if it is truely basic PHP, it wouldn't hurt to give an answer. And I will google "creating processing form PHP" while im at it. thanks. :) –  user1936894 Jan 15 '13 at 2:06
    
Close-voted as not a real question: "It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form." Yes, this can be done, but the question scope is so overly broad as to constitute work for me for free. Have a look at add_query_arg() for adding query parameters from your select field and get_query_var() for retrieving/using them. –  Chip Bennett Jan 15 '13 at 14:24
add comment

2 Answers 2

up vote 0 down vote accepted

Here's a simple example of a PHP dropdown, hope this helps.

<select name="mydropdownlist">
<?php
    $options = array('option1' => 'option 1'
                 'option2' => 'option 2'
                 'option3' => 'option 3');

    foreach($options as $value => $caption)
   {
        echo "<option value=\"$value\">$caption</option>";
   }
?>
</select>
share|improve this answer
add comment

You could have a dropdown menu like (in HTML):

<select name="query">
    <option value="0">Select Query</option>
    <option value="1">Query 1</option>
    <option value="2">Query 2</option>
    ...
</select>

And then use the following PHP:

$query = '';

switch( $_POST['query'] ) {
    case '2':
        $query = ''; // your query
        break;
    case '1':
        $query = ''; // your query
        break;
    default:
    case '0':
        $query = 'gdsr_sort=rating';
        break;
}

// The Query
query_posts( $query );

// The Loop
while ( have_posts() ) : the_post();
?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php 
endwhile;

// Reset Query
wp_reset_query();
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.