817 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+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
  • Has been part of the Envato Community for over 6 years
  • Has referred 1+ members
  • Located in Canada
  • Has collected more than 1000 items on Envato Market
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?

817 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+5 more
Gareth_Gillman says

Frontend

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

595 posts Themes and Graphics
  • Has been part of the Envato Community for over 5 years
  • Has referred 50+ members
  • Has sold $250,000+ on Envato Market
  • Has been a beta tester for an Envato feature
+9 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 ;)

817 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+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

    3497 posts
    • Elite Author: Sold more than $75,000 on Envato Market
    • Has sold $750,000+ on Envato Market
    • Located in United States
    • Helps us moderate the forums
    +10 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.

    Helpful Information

    • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
    • Open a support ticket if you would like specific help with your account, deposits or purchases.
    • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

    Most of all, enjoy your time here. Thank you for being a valued Envato community member.

    Post Reply

    Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

    <strong></strong> to make things bold
    <em></em> to emphasize
    <ul><li> or <ol><li> to make lists
    <h3> or <h4> to make headings
    <pre></pre> for code blocks
    <code></code> for a few words of code
    <a></a> for links
    <img> to paste in an image (it'll need to be hosted somewhere else though)
    <blockquote></blockquote> to quote somebody

    :grin: :shocked: :cry: Complete List of Smiley Codes

    by
    by
    by
    by
    by
    by