Support

Account

Home Forums General Issues Order result using value with float type

Unread

Order result using value with float type

  • I have 10 guides registered on my WordPress. Each guide have a version (2.7, 2.8, 2.9, 2.10). The type of custom version field are text.

    I’m trying order this using version, but the output version is 2.9, not 2.10:

    
    $last_guide = new WP_Query( array(
    	'post_type'      => 'guide',
    	'posts_per_page' => 1,
    	'meta_key'       => 'version',
    	'orderby'        => 'meta_value_num',
    	'order'          => 'DESC'
    ) );
    
    
    SELECT
        SQL_CALC_FOUND_ROWS wp_posts.ID
    FROM
        wp_posts
        INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id)
    WHERE
        1 = 1
        AND (wp_postmeta.meta_key = 'version')
        AND wp_posts.post_type = 'guide'
        AND (
            wp_posts.post_status = 'publish'
            OR wp_posts.post_status = 'acf-disabled'
            OR wp_posts.post_status = 'private'
        )
    GROUP BY
        wp_posts.ID
    ORDER BY
        wp_postmeta.meta_value + 0 DESC
    LIMIT
        0, 1
    

    What can I do to fix it? Thanks.

Viewing 1 post (of 1 total)

The topic ‘Order result using value with float type’ is closed to new replies.