Automatically Create a Custom Field


Sponsored Links






WP Canyon did wonderful tricks, this tricks is about how to automatically create a custom field when a post is published. This wonderful method is added some code on your functions.php files on your current theme.

Added Custom Field Automatically On Post - Abigail Clancy

Added Custom Field Automatically On Post - Abigail Clancy


The first time need to do is open your functions.php and paste Automatically Create a Custom Field code

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);
	}
}

You’ll need to tweak this code to make it suitable on your cases, example you need to change field-name and the custom value of your custom field. Do you like Automatically Create a Custom Field tricks?

Subscribe to Full RSS Feed

RSS FeedIf you thing this article useful, please consider subscribing to our RSS Feed or e-mail updates and stay updated with us. You can also follow @WPTricksNet on twitter for latest updates.

About WP Tricks

We are WordPress Family, we collected and writed useful tips and tricks for you WordPress. We share it for you...

Related Tips and Trick from Local Data and on The Net

Create Custom Page with Custom Loop and Query

Created WordPress as CMS? I am guarantee you’ll need this tricks. Because WordPress Custom Page is Gregorius tools we can use to create custom design/layout and whatever we want. I will show you how to Create Custom Page with Custom … Read More

How To Automatically added FTP detail on WordPress

On some web server, we need to put username, password and server address when we need to enable automatically update our WordPress, plugin or themes. This is really bad if we must input this field each time updated. Now I … Read More

How To Create Custom Widgets

WordPress is the most Usable Publishing System I ever use and found, there are so many blogger and internet writer uses WordPress on they blog. WordPress has many free themes and plugins, the other reason is, they add nice featured … Read More

How To Create “Dynamics Statics” Pages

There are so many WordPress Tricks that we can apply. In our current section we will show you, how to create "Dynamics" "Statics" Pages in WordPress. That's I mean on this point is simple. We will generated semi automatics pages … Read More

Create a Side Blog with WordPress 3.0

If you need to know How To Create a Side Blog with WordPress 3.0, I will show you how to do it. This tutorial is original created by CatsWhoCode, Thanks for share this wonderful tricks. Like on my other Tricks … Read More

How To Automatically add Twitter and Facebook buttons to your posts

How To Automatically add Twitter and Facebook buttons to your posts, this trick original created by Dev7Studios and I will share it again for you. Like on many many WP Tutorials that I was write on WP Tricks, you need … Read More

Automatically Create a Custom Field / WordPress Tricks & Tips

The first time need to do is open your functions.php and paste Automatically Create a Custom Field code. add_action('publish_page', 'add_custom_field_automatically read more

Source: http://wptricks.net/automatically-create-a-custom-field/

How to automatically create a custom field when a post is published

Daily recipes to cook with WordPress Ever wanted to be able to automatically create a custom field with a value when a post (or page) is created? read more

Source: http://www.wprecipes.com/how-to-automatically-create-a-custom-field-when-a-post-is-published

Workflow - automatically create discussion item using title field

Workflow - automatically create discussion item using title field of of custom list item as its subj. Anyone any ideas as to how I can configure SharePoint to create read more

Source: http://www.dotnetspark.com/links/19755-workflow---automatically-create-discussion.aspx

Creating Custom Metadata Fields | Brightcove Support

Click Add Custom Fields. Enter a display name for your field. This will appear as the label for the field in the Media module. We automatically create an internal name for read more

Source: http://support.brightcove.com/en/docs/creating-custom-metadata-fields

Thread Workflow - automatically create discussion item using title

Thread: Workflow - automatically create discussion item using title field of of custom list item as its subject ( on_create read more

Source: http://boardreader.com/thread/Workflow_automatically_create_discussion_56853__70f181ef-2765-4fa7-b1f4-423f63c7194d.html


3 Responses to Automatically Create a Custom Field

  1. Good trick. I would like to do this only when the publish action is on a specfic custom post type. Can it be done?

    For example, I have a custom post type called journal. When I hit publish, I want a custom field called ‘custom_post_template’ to be created with the value journalentry.php

    Any thoughts? Thanks!!

  2. Robert Lewis says:

    Can you use this method to add multiple custom fields?

  3. Pingback: How To Automatically added FTP detail on WordPress | Jhez3R

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>