2

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/

1 Answer 1

2

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>
1
  • 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? Commented Jun 12, 2012 at 11:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.