How to query posts that have certain post meta keys, and sort by meta key and/or value

I'm using this structure to make album lists. I'm using a key so I correspond lists to albums but I don't know how to reverse the output so the items start at the top with lowest key value. Any ideas?

  ?php
 $album = get_post_meta($post-ID, "album", false);
 $album_list = get_post_meta($post-ID, "album_list", false); 
 foreach ($album_list as $album_list) {
     list($key, $value) = explode(',',$album_list);
     $indexed_album_list[$key] = $value;
 }
 foreach ( $album as $each_album) {
     list($key,$album) = explode(',',$each_album);
     echo 'div'.$album.'/div';
     echo 'div';
     if ($album_list = $indexed_album_list[$key]) {
         echo $album_list;
     }  
     else {
         echo 'nbsp';
     }
     echo '/div';
 }
?    

Topic lists custom-field Wordpress

Category Web


how about array_reverse()

http://php.net/manual/en/function.array-reverse.php

there are a bunch of array manipulation functions at php.net. i'm always there looking something up. also sort() might be useful

EDIT based on your comments:

sort($album);
print_r($album);

should return:

Array
(
    [0] => 001,Get Rich Or Die Tryin
    [1] => 002,Curtis
    [2] => 003,The Massacre
    [3] => 004,Before I Self Destruct
)

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.