Title: Filter posts using dropdown.
Last modified: August 20, 2016

---

# Filter posts using dropdown.

 *  [cw17s0n](https://wordpress.org/support/users/cw17s0n/)
 * (@cw17s0n)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/filter-posts-using-dropdown/)
 * I have a page that lists a profile post for each user(agent) of my site. Existing
   code below, shows all agents ordered by last name, removes one of the users from
   the list and sticks them at the end.
 * I’d like to be able to use a drop down to filter the results on the page. The
   dropdown would populate with data gathered from the agents posts. I’d like to
   be able to filter the results on the page using meta_key and several custom taxonomies.
 * Example if I click the cities dropdown, and select Lakewood, I want to see all
   posts where ‘meta_key’ => ‘rw_city’ is Lakewood.
 * I think it breaks down to dynamically changing `'orderby' => 'meta_value', 'meta_key'
   => 'rw_lname',` using a dropdown populated with meta_key’s and taxonomies.
 * Thanks
 *     ```
       <?php
         $loop = new WP_Query( array(
           'post_type' => 'agents',
           'orderby' => 'meta_value',
           'meta_key' => 'rw_lname',
           'order'=>'ASC',
           'meta_query' => array(array( 'key' => 'rw_lname' )),
           'post__not_in' => array( '93' ),
           'posts_per_page' => -1 ) );
         $loop2 = new WP_Query( array(
           'post_type' => 'agents',
           'post__in' => array( '93' ) ) );
       ?>
       <?php
         if($loop->have_posts() || $loop2->have_posts()) {
         if($loop->have_posts()) { while($loop->have_posts()) { $loop->the_post();
       ?>
       ```
   

The topic ‘Filter posts using dropdown.’ is closed to new replies.

## Tags

 * [front-end](https://wordpress.org/support/topic-tag/front-end/)
 * [taxonomies](https://wordpress.org/support/topic-tag/taxonomies/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [cw17s0n](https://wordpress.org/support/users/cw17s0n/)
 * Last activity: [14 years, 12 months ago](https://wordpress.org/support/topic/filter-posts-using-dropdown/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
