Changeset 4373
- Timestamp:
- 10/11/2006 09:19:10 AM (18 years ago)
- Location:
- branches/2.0/wp-includes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.0/wp-includes/functions.php
r4344 r4373 422 422 global $wpdb, $post_meta_cache; 423 423 424 $post_id = (int) $post_id; 425 424 426 if ( $unique ) { 425 if ( $wpdb->get_var("SELECT meta_key FROM $wpdb->postmeta WHERE meta_key 426 = '$key' AND post_id = '$post_id'") ) { 427 if ( $wpdb->get_var("SELECT meta_key FROM $wpdb->postmeta WHERE meta_key = '$key' AND post_id = '$post_id'") ) { 427 428 return false; 428 429 } … … 435 436 $wpdb->query("INSERT INTO $wpdb->postmeta (post_id,meta_key,meta_value) VALUES ('$post_id','$key','$value')"); 436 437 437 $post_meta_cache[ '$post_id'][$key][] = $original;438 $post_meta_cache[$post_id][$key][] = $original; 438 439 439 440 return true; … … 443 444 global $wpdb, $post_meta_cache; 444 445 446 $post_id = (int) $post_id; 447 445 448 if ( empty($value) ) { 446 $meta_id = $wpdb->get_var("SELECT meta_id FROM $wpdb->postmeta WHERE 447 post_id = '$post_id' AND meta_key = '$key'"); 448 } else { 449 $meta_id = $wpdb->get_var("SELECT meta_id FROM $wpdb->postmeta WHERE 450 post_id = '$post_id' AND meta_key = '$key' AND meta_value = '$value'"); 449 $meta_id = $wpdb->get_var("SELECT meta_id FROM $wpdb->postmeta WHERE post_id = '$post_id' AND meta_key = '$key'"); 450 } else { 451 $meta_id = $wpdb->get_var("SELECT meta_id FROM $wpdb->postmeta WHERE post_id = '$post_id' AND meta_key = '$key' AND meta_value = '$value'"); 451 452 } 452 453 … … 455 456 456 457 if ( empty($value) ) { 457 $wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id = '$post_id' 458 AND meta_key = '$key'"); 459 unset($post_meta_cache['$post_id'][$key]); 460 } else { 461 $wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id = '$post_id' 462 AND meta_key = '$key' AND meta_value = '$value'"); 463 $cache_key = $post_meta_cache['$post_id'][$key]; 458 $wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id = '$post_id' AND meta_key = '$key'"); 459 unset($post_meta_cache[$post_id][$key]); 460 } else { 461 $wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id = '$post_id' AND meta_key = '$key' AND meta_value = '$value'"); 462 $cache_key = $post_meta_cache[$post_id][$key]; 464 463 if ($cache_key) foreach ( $cache_key as $index => $data ) 465 464 if ( $data == $value ) 466 unset($post_meta_cache[ '$post_id'][$key][$index]);467 } 468 469 unset($post_meta_cache[ '$post_id'][$key]);465 unset($post_meta_cache[$post_id][$key][$index]); 466 } 467 468 unset($post_meta_cache[$post_id][$key]); 470 469 471 470 return true; … … 474 473 function get_post_meta($post_id, $key, $single = false) { 475 474 global $wpdb, $post_meta_cache; 475 476 $post_id = (int) $post_id; 476 477 477 478 if ( isset($post_meta_cache[$post_id][$key]) ) { … … 508 509 global $wpdb, $post_meta_cache; 509 510 511 $post_id = (int) $post_id; 512 510 513 $original_value = $value; 511 514 if ( is_array($value) || is_object($value) ) … … 516 519 $prev_value = $wpdb->escape(serialize($prev_value)); 517 520 518 if (! $wpdb->get_var("SELECT meta_key FROM $wpdb->postmeta WHERE meta_key 519 = '$key' AND post_id = '$post_id'") ) { 521 if (! $wpdb->get_var("SELECT meta_key FROM $wpdb->postmeta WHERE meta_key = '$key' AND post_id = '$post_id'") ) { 520 522 return false; 521 523 } 522 524 523 525 if ( empty($prev_value) ) { 524 $wpdb->query("UPDATE $wpdb->postmeta SET meta_value = '$value' WHERE 525 meta_key = '$key' AND post_id = '$post_id'"); 526 $cache_key = $post_meta_cache['$post_id'][$key]; 526 $wpdb->query("UPDATE $wpdb->postmeta SET meta_value = '$value' WHERE meta_key = '$key' AND post_id = '$post_id'"); 527 $cache_key = $post_meta_cache[$post_id][$key]; 527 528 if ( !empty($cache_key) ) 528 529 foreach ($cache_key as $index => $data) 529 $post_meta_cache['$post_id'][$key][$index] = $original_value; 530 } else { 531 $wpdb->query("UPDATE $wpdb->postmeta SET meta_value = '$value' WHERE 532 meta_key = '$key' AND post_id = '$post_id' AND meta_value = '$prev_value'"); 533 $cache_key = $post_meta_cache['$post_id'][$key]; 530 $post_meta_cache[$post_id][$key][$index] = $original_value; 531 } else { 532 $wpdb->query("UPDATE $wpdb->postmeta SET meta_value = '$value' WHERE meta_key = '$key' AND post_id = '$post_id' AND meta_value = '$prev_value'"); 533 $cache_key = $post_meta_cache[$post_id][$key]; 534 534 if ( !empty($cache_key) ) 535 535 foreach ($cache_key as $index => $data) 536 536 if ( $data == $original_prev ) 537 $post_meta_cache[ '$post_id'][$key][$index] = $original_value;537 $post_meta_cache[$post_id][$key][$index] = $original_value; 538 538 } 539 539 … … 1445 1445 $post_meta_cache = array(); 1446 1446 foreach ($meta_list as $metarow) { 1447 $mpid = $metarow['post_id'];1447 $mpid = (int) $metarow['post_id']; 1448 1448 $mkey = $metarow['meta_key']; 1449 1449 $mval = $metarow['meta_value']; -
branches/2.0/wp-includes/template-functions-post.php
r4368 r4373 201 201 $post_id = $id; 202 202 203 $post_id = (int) $post_id; 204 203 205 if ( isset($post_meta_cache[$post_id]) ) 204 206 return $post_meta_cache[$post_id]; … … 208 210 $post_meta_cache = array(); 209 211 foreach ( $meta_list as $metarow ) { 210 $mpid = $metarow['post_id'];212 $mpid = (int) $metarow['post_id']; 211 213 $mkey = $metarow['meta_key']; 212 214 $mval = $metarow['meta_value']; … … 257 259 // this will probably change at some point... 258 260 function the_meta() { 259 global $id , $post_meta_cache;261 global $id; 260 262 261 263 if ( $keys = get_post_custom_keys() ) {
Note: See TracChangeset
for help on using the changeset viewer.