2017-04-13 10 views
0

カスタムフィールドでループをソートしようとしていますが、動作していません。 私は1200,1300,1400,1500,12500,13500のデータを持っているようですが、このように並べ替えるべきですが、今は1200,12500,1300,13500,1400,1500のように見えます。私のコードを見て、私に知らせてください私は間違っています。WordPressでカスタムフィールドの並べ替えが正しく機能しない

コード:事前に

<?php 
         $args = array(
           'post_status' => 'publish', 
           'post_type' => 'car', 
           'car_type' => 'suv', 
          'meta_key' => 'per_month_rent', 
          'orderby' => 'meta_value', 
          'order' => 'ASC', 
           'posts_per_page' => -1 
          // Several more arguments could go here. Last one without a comma.             
         ); 

       ?> 
<div style="display: block;clear: both;"> 
        <?php 
         // Query the posts: 
         $obituary_query = new WP_Query($args); 
         // Loop through the obituaries: 
         while ($obituary_query->have_posts()) : $obituary_query->the_post(); 
          // Echo some markup 
         $image = wp_get_attachment_image_src(get_field('image'), 'best-seller-size'); 
         $type=get_field('car_type'); 
         $company=get_field('company_name'); 
          include 'featured_list.php'; 
         endwhile; 
         // Reset Post Data 
         wp_reset_postdata(); 
        ?> 

       </div> 

感謝。

答えて

0

数値の値がの文字列であるためです。

変更ご注文から:

'orderby' => 'meta_value' 

へ:あなたの答えのための

'orderby' => 'meta_value_num' # Observe _num 
+0

おかげで、私はこれを選択しています理由です私はすでに解決策を見つけましたが、あなたは最初のものであり、あなたの答えが正しいですか回答。 –

関連する問題