• Hello !

    I made a mysql query to wordpress like this:

    <?php
     $querystr = "
            SELECT $wpdb->posts.*
            FROM $wpdb->posts, $wpdb->postmeta
            WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id
    	AND $wpdb->postmeta.meta_key = 'where'
        	AND $wpdb->postmeta.meta_value = 'london'
            LIMIT 0,50
     ";
     $pageposts = $wpdb->get_results($querystr, OBJECT);
    
     ?>

    In this way i can grab all posts with meta_key = “where” and meta_value = london

    The problem is that i’ve also another meta_key, “date” and a meta_value that contain the real date like “05-06-2013”, “06-06-2013”, etc.

    How i can query all posts with meta “where” = “london” and order by date using the data contain in meta “date” = “xx-xx-xxxx”.

    Thanks for the help.In this way i can grab all posts with meta_key = “where” and meta_value = london

    The problem is that i’ve also another meta_key, “date” and a meta_value that contain the real date like “05-06-2013”, “06-06-2013”, etc.

    Thanks !

Viewing 1 replies (of 1 total)
  • You cannot sort dates in that format. You will either need to store the dates in ‘yyyy-mm-dd’ format, or alter the query to create a sort key in the correct format.

Viewing 1 replies (of 1 total)
  • The topic ‘Mysql query and order meta value’ is closed to new replies.