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 need to add a taxonomy dropdwon filter in archive page so that I can display the posts assigned to selected taxonomy.

Here is the HTML Output for taxonomies:

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  <select name="services" id="selectservice" class="postform" onchange="submit();">
    <option value="">Select Service</option>
    <option value="intensive-support">Intensive Support</option>
    <option value="recovery-work">Recovery Work</option>
    <option value="tenant-support">Tenant Support</option>
  </select>
</form>

Below is the Query Code :

<table class="dataTable">
    <tr>
      <th>Name</th>
      <th>Location</th>
      <th>Website</th>
      <th>Service(s)</th>
    </tr>
    <?php $service_query = new WP_Query('post_type=ptype_service&posts_per_page=-1'); ?>
    <?php $j = 0 ?>
    <?php while ($service_query->have_posts()) : $service_query->the_post(); ?>
    <?php $additional_class = (++$j % 2 == 0) ? 'even' : 'odd'; ?>
    <tr class="<?php echo $additional_class ?>">
      <td><?php the_title()?></td>
      <td><?php echo (get_post_meta($post->ID, 'pir_groups_location', true))?></td>
      <td><a target="_blank" href="http://<?php echo (get_post_meta($post->ID, 'pir_groups_website', true))?>"><?php echo (get_post_meta($post->ID, 'pir_groups_website', true))?></a></td>
      <td>
        <?php
        $terms = get_the_terms( $post->ID, 'services' );
        if ( $terms && ! is_wp_error( $terms ) ) :      
            $services_links = array();  
            foreach ( $terms as $term ) {
                $services_links[] = $term->name;
            }                               
            $on_draught = join( ", ", $services_links );
        ?>
        <?php echo $on_draught; ?>
        <?php endif; ?>
      </td>
    </tr>
    <?php endwhile; ?>
  </table>

Regards

share|improve this question

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.