WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

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 need help in sorting lists of posts inside a static page by a custom field value. I'm currently using the code below but it is not sorting correctly.

            $postslist = get_posts('numberposts=15&order=DESC&meta_key=sorting&orderby=meta_value_number&tag='. get_post_meta($post->ID, 'Tag', true));
            foreach ($postslist as $post) :

Any help would be appreciated.

share|improve this question

See the answers to this question: WordPress how to sort by meta value?

share|improve this answer

You Should use meta_key_num instead of meta_key_number, so args for get_posts would be like this:


$post_list_args = array(
   'numberposts' => 15,
   'order' => 'DESC',
   'orderby' => 'meta_key_num',
   'meta_key' => 'sorting',
   'tag' => get_post_meta($post->ID, 'Tag', true),

$post_list = get_posts( $post_list_args );
foreach ( $post_list as $post ) :
   setup_postdata( $post );

share|improve this answer

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.