Skip to content

Instantly share code, notes, and snippets.

@miya0001
Created February 17, 2014 10:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miya0001/9048229 to your computer and use it in GitHub Desktop.
Save miya0001/9048229 to your computer and use it in GitHub Desktop.
add_meta_box()で追加したUIで保存したカスタムフィールドのデータが消えるのを防ぐ
<?php
add_action("save_post", "save_post_meta");
function save_post_meta($id)
{
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { // オートセーブの時は何もしない
return $id;
}
if (isset($_POST['action']) && $_POST['action'] == 'inline-save') { // クイックポストの時は何もしない
return $id;
}
if (isset($_POST['featured']) && $_POST['featured']) {
update_post_meta($id, '_featured', $_POST['featured_order']);
} else {
delete_post_meta($id, '_featured');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment