Update meta before updating the post so that page_template is not stomped. fixes #1933

git-svn-id: http://svn.automattic.com/wordpress/trunk@3190 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2005-11-22 00:36:36 +00:00
parent 2d46d957a6
commit 73dde55507
3 changed files with 24 additions and 26 deletions

View File

@ -175,25 +175,23 @@ function edit_post() {
$_POST['post_date_gmt'] = get_gmt_from_date("$aa-$mm-$jj $hh:$mn:$ss");
}
// Meta Stuff
if ($_POST['meta']) {
foreach ($_POST['meta'] as $key => $value)
update_meta($key, $value['key'], $value['value']);
}
if ($_POST['deletemeta']) {
foreach ($_POST['deletemeta'] as $key => $value)
delete_meta($key);
}
add_meta($post_ID);
wp_update_post($_POST);
// Now that we have an ID we can fix any attachment anchor hrefs
fix_attachment_links($_POST['ID']);
// Meta Stuff
if ($_POST['meta'])
: foreach ($_POST['meta'] as $key => $value)
: update_meta($key, $value['key'], $value['value']);
endforeach;
endif;
if ($_POST['deletemeta'])
: foreach ($_POST['deletemeta'] as $key => $value)
: delete_meta($key);
endforeach;
endif;
add_meta($post_ID);
fix_attachment_links($post_ID);
return $post_ID;
}

View File

@ -184,9 +184,7 @@ function wp_insert_post($postarr = array()) {
} else if ($post_status == 'static') {
generate_page_rewrite_rules();
if ( empty($page_template) )
$page_template = 'Default Template';
if ( !empty($page_template) )
if ( ! update_post_meta($post_ID, '_wp_page_template', $page_template))
add_post_meta($post_ID, '_wp_page_template', $page_template, true);
}

View File

@ -510,12 +510,14 @@ function update_post_meta($post_id, $key, $value, $prev_value = '') {
$wpdb->query("UPDATE $wpdb->postmeta SET meta_value = '$value' WHERE
meta_key = '$key' AND post_id = '$post_id'");
$cache_key = $post_meta_cache['$post_id'][$key];
if ( !empty($cache_key) )
foreach ($cache_key as $index => $data)
$post_meta_cache['$post_id'][$key][$index] = $original_value;
} else {
$wpdb->query("UPDATE $wpdb->postmeta SET meta_value = '$value' WHERE
meta_key = '$key' AND post_id = '$post_id' AND meta_value = '$prev_value'");
$cache_key = $post_meta_cache['$post_id'][$key];
if ( !empty($cache_key) )
foreach ($cache_key as $index => $data)
if ( $data == $original_prev )
$post_meta_cache['$post_id'][$key][$index] = $original_value;