Posted By

wpCanyon on 11/17/10


Tagged

wordpress


Versions (?)

Adding A Custom Field Automatically On Post/Page Publish


 / Published in: PHP
 

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

  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. }

Report this snippet  

You need to login to post a comment.