Changeset 4419 for trunk/wp-includes/post.php
- Timestamp:
- 10/24/2006 10:52:59 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/post.php
r4409 r4419 275 275 $post_id = (int) $post_id; 276 276 277 if ( isset($post_meta_cache[$post_id][$key]) ) { 278 if ( $single ) { 279 return maybe_unserialize( $post_meta_cache[$post_id][$key][0] ); 280 } else { 281 return maybe_unserialize( $post_meta_cache[$post_id][$key] ); 282 } 283 } 284 285 $metalist = $wpdb->get_results("SELECT meta_value FROM $wpdb->postmeta WHERE post_id = '$post_id' AND meta_key = '$key'", ARRAY_N); 286 287 $values = array(); 288 if ( $metalist ) { 289 foreach ($metalist as $metarow) { 290 $values[] = $metarow[0]; 291 } 292 } 277 if ( !isset($post_meta_cache[$post_id]) ) 278 update_postmeta_cache($post_id); 293 279 294 280 if ( $single ) { 295 if ( count($values) ) {296 $return = maybe_unserialize( $values[0]);297 } else {281 if ( isset($post_meta_cache[$post_id][$key][0]) ) 282 return maybe_unserialize($post_meta_cache[$post_id][$key][0]); 283 else 298 284 return ''; 299 } 300 } else { 301 $return = $values; 302 } 303 304 return maybe_unserialize($return); 285 } else { 286 return maybe_unserialize($post_meta_cache[$post_id][$key]); 287 } 305 288 } 306 289 … … 341 324 342 325 343 function get_post_custom( $post_id = 0) {326 function get_post_custom($post_id = 0) { 344 327 global $id, $post_meta_cache, $wpdb; 345 328 346 if ( ! 329 if ( !$post_id ) 347 330 $post_id = $id; 348 331 349 332 $post_id = (int) $post_id; 350 333 351 if ( isset($post_meta_cache[$post_id]) ) 352 return $post_meta_cache[$post_id]; 353 354 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) ) { 355 // Change from flat structure to hierarchical: 356 $post_meta_cache = array(); 357 foreach ( $meta_list as $metarow ) { 358 $mpid = (int) $metarow['post_id']; 359 $mkey = $metarow['meta_key']; 360 $mval = $metarow['meta_value']; 361 362 // Force subkeys to be array type: 363 if ( !isset($post_meta_cache[$mpid]) || !is_array($post_meta_cache[$mpid]) ) 364 $post_meta_cache[$mpid] = array(); 365 366 if ( !isset($post_meta_cache[$mpid]["$mkey"]) || !is_array($post_meta_cache[$mpid]["$mkey"]) ) 367 $post_meta_cache[$mpid]["$mkey"] = array(); 368 369 // Add a value to the current pid/key: 370 $post_meta_cache[$mpid][$mkey][] = $mval; 371 } 372 return $post_meta_cache[$mpid]; 373 } 334 if ( !isset($post_meta_cache[$post_id]) ) 335 update_postmeta_cache($post_id); 336 337 return $post_meta_cache[$post_id]; 374 338 } 375 339 … … 377 341 $custom = get_post_custom( $post_id ); 378 342 379 if ( ! 343 if ( !is_array($custom) ) 380 344 return; 381 345
Note: See TracChangeset
for help on using the changeset viewer.