0
votes

i heve the following loop:

$argsvs = array( 
                'post_type' => 'imovel-para-venda', 
                'meta_key' => 'wpcf-imovel-preco',
                'posts_per_page' => 0,
                 'oderby' => 'meta_value',
                 'order' => 'DESC'
                 );

$loop = new WP_Query( $argsvs ); while ( $loop->have_posts() ) : $loop->the_post(); ..... well, the thing is that it isnt working! The meta_key 'wpfc-imovel-preco' is a custom field creating using the plugin Types. It is filled with numbers and text sometimes. Well, the code above simply doesnt sort anything :( Any ideas?

1

1 Answers

1
votes

The problem is that you have oderby instead of orderby - you missed the r in there.

I tested your code and it's otherwise working. There is only one thing to keep in mind though - number meta values will be ordered separately from string meta values, here is an example:

I have 5 pages with the following values for their custom fields: abc, acb, dcb, 3, 5. When I order them in ascending fashion, they are ordered as follows:

  1. 3
  2. 5
  3. abc
  4. acb
  5. dcb

If you switch back to descending, you get:

  1. dcb
  2. acb
  3. abc
  4. 5
  5. 3