• Resolved freshifreshy

    (@freshifreshy)


    I’m trying to order by a numerical value (a price). I followed the adivce I found on a previous post and used ORDER BY ABS(0 + $wpdb->postmeta.meta_key) ASC

    It seemed to work great, but every now and then a single entry or two will get ordered out of place. I can’t seem to figure out why, but with each of my lists, a few entries don’t seem to want to be placed in order.

    Not sure what to do about it…

    Here is my query

    $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts
    LEFT JOIN $wpdb->postmeta ON($wpdb->posts.ID = $wpdb->postmeta.post_id)
    LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
    LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
    WHERE $wpdb->term_taxonomy.term_id = 3
    AND $wpdb->term_taxonomy.taxonomy = 'category'
    AND $wpdb->posts.post_status = 'publish'
    AND $wpdb->postmeta.meta_key = 'Price'
    ORDER BY ABS(0 + $wpdb->postmeta.meta_key) ASC
    LIMIT $offset, $postsperpage", OBJECT);

    Thanks!

  • The topic ‘Orderby Problems’ is closed to new replies.