WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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>";

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
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>";
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


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.