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

I have a series of posts (using a wp-zoom theme). I would like to create a custom field called order and sort by that field.

Here is part of my homepage code:

$z = count($wpzoom_exclude_cats_home);
if ($z > 0) { 
    $x = 0; 
    $que = ""; 
    while ($x < $z) {
        $que .= "-".$wpzoom_exclude_cats_home[$x]; 
        if ($x < $z) {
            $que .= ",";
query_posts( $query_string . "&cat=$que" );
if (have_posts()) : 
share|improve this question
up vote 2 down vote accepted

You can use the "orderby" parameter of query_posts.
You must specify your custom field and you must give it a numeric value. Short example:

query_posts($query_string . "&cat=$que&orderby=meta_value_num&meta_key=your_custom_field")
share|improve this answer
This is awesome - thanks so much! – redconservatory Feb 26 '11 at 1:32

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.