Ticket #3273: postmeta.diff
| File postmeta.diff, 3.8 KB (added by , 20 years ago) |
|---|
-
wp-includes/post.php
274 274 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 } 277 if ( !isset($post_meta_cache[$post_id]) ) 278 update_postmeta_cache($post_id); 284 279 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 } 293 294 if ( $single ) { 295 if ( count($values) ) { 296 $return = maybe_unserialize( $values[0] ); 297 } else { 298 return ''; 299 } 300 } else { 301 $return = $values; 302 } 303 304 return maybe_unserialize($return); 280 if ( $single ) 281 return maybe_unserialize($post_meta_cache[$post_id][$key][0]); 282 else 283 return maybe_unserialize($post_meta_cache[$post_id][$key]); 305 284 } 306 285 307 286 function update_post_meta($post_id, $key, $value, $prev_value = '') { … … 340 319 } 341 320 342 321 343 function get_post_custom( $post_id = 0) {322 function get_post_custom($post_id = 0) { 344 323 global $id, $post_meta_cache, $wpdb; 345 324 346 if ( ! $post_id )325 if ( !$post_id ) 347 326 $post_id = $id; 348 327 349 328 $post_id = (int) $post_id; 350 329 351 if ( isset($post_meta_cache[$post_id]) )352 return $post_meta_cache[$post_id];330 if ( !isset($post_meta_cache[$post_id]) ) 331 update_postmeta_cache($post_id); 353 332 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 } 333 return $post_meta_cache[$post_id]; 374 334 } 375 335 376 336 function get_post_custom_keys( $post_id = 0 ) { 377 337 $custom = get_post_custom( $post_id ); 378 338 379 if ( ! is_array($custom) )339 if ( !is_array($custom) ) 380 340 return; 381 341 382 342 if ( $keys = array_keys($custom) ) -
wp-includes/functions.php
563 563 564 564 update_post_category_cache($post_id_list); 565 565 566 update_postmeta_cache($post_id_list); 567 } 568 569 function update_postmeta_cache($post_id_list = '') { 570 global $wpdb, $post_meta_cache; 571 572 // we're marking each post as having its meta cached (with no keys), to prevent posts with no meta keys from being queried again 573 // any posts that DO have keys will have this FALSE overwritten with a proper array, down below 574 $post_id_array = explode(',', $post_id_list); 575 foreach ( (array) $post_id_array as $pid ) 576 $post_meta_cache[$pid] = false; 577 566 578 // Get post-meta info 567 579 if ( $meta_list = $wpdb->get_results("SELECT post_id, meta_key, meta_value FROM $wpdb->postmeta WHERE post_id IN($post_id_list) ORDER BY post_id, meta_key", ARRAY_A) ) { 568 580 // Change from flat structure to hierarchical: 569 $post_meta_cache = array(); 581 if ( !isset($post_meta_cache) ) 582 $post_meta_cache = array(); 583 570 584 foreach ($meta_list as $metarow) { 571 585 $mpid = (int) $metarow['post_id']; 572 586 $mkey = $metarow['meta_key'];