Skip to content

Instantly share code, notes, and snippets.

@rsharrer
Created September 25, 2013 20:31
Show Gist options
  • Save rsharrer/6705598 to your computer and use it in GitHub Desktop.
Save rsharrer/6705598 to your computer and use it in GitHub Desktop.
WP-Functions /Add custom field automatically when post or page is publish
add_action('publish_page', 'add_custom_field_automatically');
add_action('publish_post'. 'add_custom_field_automatically');
function add_custom_field_automatically($post_ID) {
global $wpdb;
if(!wp_is_post_revision($post_ID)) {
add_post_meta($post_ID, 'FIELD_NAME', 'CUSTOM VALUE', true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment