454 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 3-4 years
  • Microlancer Beta Tester
  • Referred between 1 and 9 users
  • United Kingdom
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
  • Bought between 1000 and 4999 items
  • Canada
  • Has been a member for 5-6 years
  • Referred between 1 and 9 users
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?

454 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 3-4 years
  • Microlancer Beta Tester
  • Referred between 1 and 9 users
  • United Kingdom
Gareth_Gillman says

Frontend

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

538 posts Themes and Graphics
  • Author had a File in an Envato Bundle
  • Author had a Free File of the Month
  • Bought between 100 and 499 items
  • Elite Author
  • Europe
  • Exclusive Author
  • Has been a member for 4-5 years
+4 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 ;)

454 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 3-4 years
  • Microlancer Beta Tester
  • Referred between 1 and 9 users
  • United Kingdom
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

    3365 posts
    • Elite Author
    • Sold between 250 000 and 1 000 000 dollars
    • Community Moderator
    • Bought between 50 and 99 items
    • Referred more than 2000 users
    • Has been a member for 4-5 years
    • Repeatedly Helped protect Envato Marketplaces against copyright violations
    +4 more
    sevenspark Volunteer 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