Is there a way to set default custom fields when creating a post?
This is the proper method to add custom fields support (you don’t get the blank fields when edit posts)
1 2 3 4 5 6 7 8 9 10 | function set_default_meta($post_ID){ $current_field_value = get_post_meta($post_ID,'Sort Order',true); $default_meta = '100'; // value if ($current_field_value == '' && !wp_is_post_revision($post_ID)){ add_post_meta($post_ID,'Sort Order',$default_meta,true); } return $post_ID; } add_action('wp_insert_post','set_default_meta'); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.