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
Gareth_Gillman said
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?
Frontend
Basically it should display a list of manufacturers and a link to their page.
- Author had a File in an Envato Bundle
- Author had a Free File of the Month
- Author was Featured
- Bought between 100 and 499 items
- Europe
- Exclusive Author
- Featured in a Magazine
- Has been a member for 3-4 years
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 
Unfortunately the code you supplied didn’t work, I get no drop down options.
I modified the code to use the instead of
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
- Sold between 250 000 and 1 000 000 dollars
- Community Moderator
- Author was Featured
- Item was Featured
- Bought between 50 and 99 items
- Referred between 1000 and 1999 users
- Has been a member for 3-4 years
- Repeatedly Helped protect Envato Marketplaces against copyright violations
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.
