1096 posts
  • 5 Years of Membership
  • Affiliate Level 1
  • Beta Tester
  • Collector Level 2
+5 more
Gareth_Gillman
says

I am trying to add my taximonies to a drop down and it’s not working for some reason, it displays the actual drop down but no content.

Code:
<select name="manufacturers" onchange="document.location.href=this.options[this.selectedIndex].value;"> 
  <?php $args = array( 'post_type' ?> 'mobile_manufactuers' ); ?>
  <?php $loop = new WP_Query( $args ); ?>
  <?php while ( $loop?>have_posts() ) : $loop->the_post(); ?>
    <option value="<?php the_terms( $post->ID, '{taxonomy name}'); ?>"><?php the_terms($post?>ID, '{Displayed Title}: ', ', ', ' '); ?></option>
   <?php endwhile; ?>
  </select>

Should I be using {Displayed title} or should I be using something else.

I followed the tutorial here

Thanks In Advance

701 posts
  • 7 Years of Membership
  • Affiliate Level 1
  • Canada
  • Collector Level 6
chrismccoy
says

I am trying to add my taximonies to a drop down and it’s not working for some reason, it displays the actual drop down but no content. Code:
<select name="manufacturers" onchange="document.location.href=this.options[this.selectedIndex].value;"> 
  <?php $args = array( 'post_type' ?> 'mobile_manufactuers' ); ?>
  <?php $loop = new WP_Query( $args ); ?>
  <?php while ( $loop?>have_posts() ) : $loop->the_post(); ?>
    <option value="<?php the_terms( $post->ID, '{taxonomy name}'); ?>"><?php the_terms($post?>ID, '{Displayed Title}: ', ', ', ' '); ?></option>
   <?php endwhile; ?>
  </select>

Should I be using {Displayed title} or should I be using something else.

I followed the tutorial here

Thanks In Advance

is this for frontend or backend?

1096 posts
  • 5 Years of Membership
  • Affiliate Level 1
  • Beta Tester
  • Collector Level 2
+5 more
Gareth_Gillman
says

Frontend

Basically it should display a list of manufacturers and a link to their page.

610 posts Themes and Graphics
  • 6 Years of Membership
  • Affiliate Level 3
  • Author Level 9
  • Beta Tester
+11 more
Bebel
says

Please ! do seperate php and html as often as possible :) (always)
Next, I bet you will use it multiple times, so put it in a function somewhere.

You want to display all manufactures (categories) from the post type, right? Why are you looping the posts then? The one doesn’t have anything to do with the other, does it?
All you have to do: get all categories from this post type. Here’s how we solve it (or did in our last theme)

/**
 * gets a list of terms of a given taxonomy
 *
 * @param string $taxonomy
 * @return string
 */
function bebel_get_term_list($taxonomy) {

  $terms = get_terms($taxonomy);

  $li = '';
  foreach($terms as $term) {
    $li .= '<li><a href="'.get_home_url().'?'.$taxonomy.'='.$term->slug.'">'.$term->name.'</a></li>';
  }
  return $li;
}

All you have to do now is:

<select name="manufacturers" onchange="document.location.href=this.options[this.selectedIndex].value;"> 
  <?php echo bebel_get_term_list('mobile_manufacturers'); ?>
</select>

And it will get you a list of options.

Feel free to rename the function, though ;)

1096 posts
  • 5 Years of Membership
  • Affiliate Level 1
  • Beta Tester
  • Collector Level 2
+5 more
Gareth_Gillman
says

Unfortunately the code you supplied didn’t work, I get no drop down options.

I modified the code to use the instead of

  • and the drop down shows but there is no text for the drop down and the urls go to /mobile/?mobile_manufacturers=
  • My code looks like:

     function manufacture_list($taxonomy) {
      $terms = get_terms($taxonomy);
      $li = '';
      foreach($terms as $term) {
        $li .= '<option value="'.get_home_url().'?'.$taxonomy.'='.$term->slug.'">'.$term->name.'</option>';
      }
      return $li;
     }
    
    <select name="manufacturers" onchange="document.location.href=this.options[this.selectedIndex].value;"> 
       <option value=""><- Select Manufacturer -></option>
        <?php echo manufacture_list('mobile_manufacturers'); ?>
      </select>
    

    Thanks in advance

    3535 posts
    • Power Elite Author
    • Author Level 12
    • Trendsetter
    • United States
    +13 more
    sevenspark
    Moderator
    says

    Why not use wp_dropdown_categories and specify the taxonomy argument?

    http://codex.wordpress.org/Template_Tags/wp_dropdown_categories

    Then use jQuery to handle your javascript events.

    by
    by
    by
    by
    by
    by