Adding A Custom Field Automatically On Post/Page Publish


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. add_action('publish_page', 'add_custom_field_automatically');
  2. add_action('publish_post', 'add_custom_field_automatically');
  3. function add_custom_field_automatically($post_ID) {
  4. global $wpdb;
  5. if(!wp_is_post_revision($post_ID)) {
  6. add_post_meta($post_ID, 'field-name', 'custom value', true);
  7. }
  8. }

URL: http://wpcanyon.com/tipsandtricks/adding-a-custom-field-automatically-on-postpage-publish/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.