Skip to content

Instantly share code, notes, and snippets.

@ewistrand
Created November 19, 2015 14:57
Show Gist options
  • Save ewistrand/6d207d9f221dcf07def3 to your computer and use it in GitHub Desktop.
Save ewistrand/6d207d9f221dcf07def3 to your computer and use it in GitHub Desktop.
WP Add default custom fields to posts
<?php
/**
* Add Default Custom Fields To Posts
* Note: This is just an example.
*/
add_action('wp_insert_post', 'set_default_custom_fields');
function set_default_custom_fields($post_id){
// slides can be post or any custom post type
if ( $_GET['post_type'] == 'slides' ) {
add_post_meta($post_id, 'subtitle', '', true);
add_post_meta($post_id, 'description', '', true);
add_post_meta($post_id,'link_url','',TRUE);
add_post_meta($post_id,'link_label','',TRUE);
}
return true;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment