• Resolved crashfellow

    (@crashfellow)


    Hi There,

    I’ve created a custom post type, with post meta. The field name is ‘price_two’. This field contains float values such as :

    11.95
    13.50
    9.23 etc

    Now when using this query:

    $query = new WP_Query(
        array(
          'post_type'=>'product',
          'types' => $term->slug,
          'orderby' => 'meta_value_num',
          'meta_key' => 'price_two',
          'order' => 'ASC',
          'paged' => $paged
        )
      );

    It returns the posts sorted as if sorted by a string. I’ve attempted multiple ways around this I’ve found in Google, such a putting meta_value in front of meta_value_num.

    The values are currently sorted for example, in this order:
    9.95
    12.95
    11.95
    14.95
    16.95
    13.95

    Is there a way around this? essentially i need it to be sorted based on the float value.

  • The topic ‘Issue with ordering meta_value_num on post meta’ is closed to new replies.