• 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.