Posted By

baires on 08/11/10


wordpress field custom

Versions (?)

Adding A Custom Field Automatically On Post/Page Publish

 / Published in: PHP


Little code snippet for automatically adding a custom field for a page or post when they are published.

  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.