The below code will add default custom fields to your post ( Insert the code in your themes function.php ) .
add_action('wp_insert_post', 'set_default_custom_fields');
function set_default_custom_fields($post_id){
if ( $_GET['post_type'] == 'post' ) {
add_post_meta($post_id, 'Field Name', '', true);
add_post_meta($post_id, 'Another Field Name', '', true);
}
return true;
}
By default this will add an empty custom field to your post. If you want to enter a value by default too, use the code below.
add_action('wp_insert_post', 'set_default_custom_fields');
function set_default_custom_fields($post_id){
if ( $_GET['post_type'] == 'post' ) {
add_post_meta($post_id, 'Field Name', 'Field Value', true);
}
return true;
}
Related Posts:
- How to protect pages with double authentication: password + email (in custom field)
- How set featured posts using checkbox in post edit screen?
- Add a checkbox to post screen that adds a class to the title
- Custom Field in Featured image for A particular post
- Convert custom fields to post categories
- Update all posts automatically when using post_meta
- I am trying to create a simple frontend form for posting
- HTML code in Custom field
- How to show posts rank based on custom field value
- Add custom field to all posts in specific category
- Adding a Nav menu to post admin
- meta_box or custom_field as a second tinymce post-instance?
- Guest Author – How to modify my custom function code if the guest author URL will follow a particular pattern/format?
- Create A Metabox For A Custom Field
- Paragraphs removed when using get_post_custom()?
- Change post format using custom field
- Populating a page with content from post custom fields
- Sanitizing `wp_editor();` Values for Database, Edit, and Display
- How can I make existing custom fields easier to edit/add in my theme?
- Add custom fields to post programmatically
- How to get Advanced Custom Field Value According using POST ID? [closed]
- Autoremove empty custom fields
- How to add a custom field after wp post
- Custom fields on a virtual page
- What Is meta_id In wp_postmeta?
- Get a custom field of all posts on current blog page
- Only display posts after current date
- Add custom field automatically (add_post_meta) with value based on number of words of article
- Global $post not working in OOP function WordPress
- How can I get a post field value using javascript?
- Automatic value for custom fields for posts
- Understanding and using metaboxes in posts
- Guest Author – How to display posts on /author/ archive page
- How can I sort posts by the date and a custom meta field?
- How do I correctly set up a WP-Query to only show upcoming event-posts?
- How to display Common posts from specific Tag & Category with Shortcode
- Automatically add custom fields value to wordpress post
- MySql query to get posts with all meta and terms
- Categories list into registration form
- Add a custom meta box in the post options that loads some html code in the header
- Query Posts With Over 1000 Views
- Cannot retrieve a custom RSS field from posts
- Hooking into the post editing screen for an existing page only
- How to rate a post from Admin Side / Manually?
- Customize rel=canonical tag for single blog post
- Get post ID from a link
- Create a list of posts with topic headdings
- Add field to user meta table in database when link is clicked
- Hide custom metabox value from custom fields
- Get post meta retrieving wrong value
- if in category but only with post meta
- Output Post with ACF Fields into other Post
- Saving Post Data in Another Database
- After ajax image is outside the “ tag
- Edit custom fields in posts list
- Add multiple meta keys to a post at once
- WP_Query custom field pass the post id
- If custom field is empty, use one from a previous post
- Why my meta boxes won’t show in front post page?
- Adding external field to my post form (admin side) and to post show (frontend side)
- How To Use Custom Fields With .mp3 Links
- how can display a post on home screen without images
- Display content between two dates?
- Will multiple category descriptions effect my search engine optimization?
- Automate post update for all posts?
- Override WordPress core post-template.php block template
- Only the most recent post is showing on my category page (working on localhost, not live site)
- Post picker custom field on page
- Post meta not working
- Adding an option to post editor to show a site disclaimer or message
- Need to display a Jan 1st post as the site’s front page on Jan 1st, and Jan 2nd post as front page on Jan 2nd etc
- Is there a way to save different data when USER interacts with the same POST?
- How do you update post date (year only) in a separate custom field?
- How to get value of a selected option from select tag and use it in WP_query to filter posts?
- How do I display posts ordered by a date custom field?
- WP_Query sort by meta_value_num or date
- Creating Ordered Query using Meta_key
- Auto populate custom fields by post date
- ACF Relationship – Get Parent’s Post Object
- Extracting a TLD from the content and assign to custom field
- How can I set and update the the_date according to a custom field of the post
- How to retrieve a post by inputing the url in a custom field and displaying it on an options page
- Custom fields in normal posts
- WP Query between posts custom fields [duplicate]
- get_the_ID() fails the first time, returns a value the second time it’s called
- Using Post ID and Page ID in same function
- Apply comment to different post (not the current post) [duplicate]
- Order posts by separate menu order for different sub-categories
- How to only allow post to be deleted if custom field doesn’t exist
- How to custom sort-out editing-panel fields?
- Delete old post with new post
- How can I create a menu items from meta box based on users input
- get_post_meta property of non object
- Home page: using custom fields for posts and pages
- How would I attach media/images to a post based on a ID stored in a each post’s custom field
- How do I insert a custom field in a user submitted post?
- How to Do Custom Fields to Output a Definition List
- How to make a local “scroll to ID” on post?
- How to detect if an ACF custom-field is really in use?
- Read more opens attachment