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.

We've set up drop down lists to allow people to filter posts based on custom post types.

In order to populate the drop down list I am using:

<?php $terms = get_terms("ratios");
$count = count($terms);
if ( $count > 0 ){
 foreach ( $terms as $term ) {
     echo "<option value='" . $term->slug . "'>" . $term->name . "</option>";
 }
}?>
</select>

The slug and the name are pretty similar, so I don't mind which one we are using.

How can I list them as integers?

The site is here if you need more of an idea: http://amigaeng.com.au/gearbox-list/

share|improve this question

1 Answer 1

up vote 2 down vote accepted

get_terms function will return an array of object. Each of them has term_id field which contains id of a term. Just use it instead of slug and you will have what you need:

<?php $terms = get_terms("ratios");
if ( $count($terms) > 0 ){
 foreach ( $terms as $term ) {
     echo "<option value='" . $term->term_id . "'>" . $term->name . "</option>";
 }
}?>
</select>
share|improve this answer
    
Thanks Eugene, I think I must have missed a bit in my questions. What I would actually like to know is how to then sort this array numerically? –  Matt Edwards Jun 12 '12 at 11:21

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.