| 196 | | if ( $post_id ) |
|---|
| 197 | | $id = $post_id; |
|---|
| 198 | | if ( isset($post_meta_cache[$id]) ) { |
|---|
| 199 | | return $post_meta_cache[$id]; |
|---|
| 200 | | } else { |
|---|
| 201 | | if ( $meta_list = $wpdb->get_results("SELECT post_id, meta_key, meta_value FROM $wpdb->postmeta WHERE post_id = '$id' ORDER BY post_id, meta_key", ARRAY_A) ) { |
|---|
| 202 | | // Change from flat structure to hierarchical: |
|---|
| 203 | | $post_meta_cache = array(); |
|---|
| 204 | | foreach ( $meta_list as $metarow ) { |
|---|
| 205 | | $mpid = $metarow['post_id']; |
|---|
| 206 | | $mkey = $metarow['meta_key']; |
|---|
| 207 | | $mval = $metarow['meta_value']; |
|---|
| 208 | | |
|---|
| 209 | | // Force subkeys to be array type: |
|---|
| 210 | | if ( !isset($post_meta_cache[$mpid]) || !is_array($post_meta_cache[$mpid]) ) |
|---|
| 211 | | $post_meta_cache[$mpid] = array(); |
|---|
| 212 | | if ( !isset($post_meta_cache[$mpid]["$mkey"]) || !is_array($post_meta_cache[$mpid]["$mkey"]) ) |
|---|
| 213 | | $post_meta_cache[$mpid]["$mkey"] = array(); |
|---|
| 214 | | |
|---|
| 215 | | // Add a value to the current pid/key: |
|---|
| 216 | | $post_meta_cache[$mpid][$mkey][] = $mval; |
|---|
| 217 | | } |
|---|
| | 196 | |
|---|
| | 197 | if ( ! $post_id ) |
|---|
| | 198 | $post_id = $id; |
|---|
| | 199 | |
|---|
| | 200 | if ( isset($post_meta_cache[$post_id]) ) |
|---|
| | 201 | return $post_meta_cache[$post_id]; |
|---|
| | 202 | |
|---|
| | 203 | if ( $meta_list = $wpdb->get_results("SELECT post_id, meta_key, meta_value FROM $wpdb->postmeta WHERE post_id = '$post_id' ORDER BY post_id, meta_key", ARRAY_A) ) { |
|---|
| | 204 | // Change from flat structure to hierarchical: |
|---|
| | 205 | $post_meta_cache = array(); |
|---|
| | 206 | foreach ( $meta_list as $metarow ) { |
|---|
| | 207 | $mpid = $metarow['post_id']; |
|---|
| | 208 | $mkey = $metarow['meta_key']; |
|---|
| | 209 | $mval = $metarow['meta_value']; |
|---|
| | 210 | |
|---|
| | 211 | // Force subkeys to be array type: |
|---|
| | 212 | if ( !isset($post_meta_cache[$mpid]) || !is_array($post_meta_cache[$mpid]) ) |
|---|
| | 213 | $post_meta_cache[$mpid] = array(); |
|---|
| | 214 | |
|---|
| | 215 | if ( !isset($post_meta_cache[$mpid]["$mkey"]) || !is_array($post_meta_cache[$mpid]["$mkey"]) ) |
|---|
| | 216 | $post_meta_cache[$mpid]["$mkey"] = array(); |
|---|
| | 217 | |
|---|
| | 218 | // Add a value to the current pid/key: |
|---|
| | 219 | $post_meta_cache[$mpid][$mkey][] = $mval; |
|---|
| | 220 | } |
|---|