I am working on a WordPress site and while creating a new posts we have certain number of custom attributes which are always part of the post, as of now we need to manually add those all custom fields while creating the post.
I am looking a way so that when we click on the new post link the template should come with this set of default custom fields with default values and admin can change them if he/she want to change any default value.
i know that there are few plugins, but i do not want to use those plugins in mean time i also have to take care that this new functionality should not break any thing as we already have thousands of published posts and i do not want them to get affected by this functionality.
Any suggestion or pointer in this regard will really be helpful.
I’d recommend creating your own plug-in for storing and updating these options.
To add the defaults, simply use the add_option function and to pull them into your custom metabox, when you check for the custom post meta, if it isn’t found, echo out the appropriate option using get_option.
You can always just hard-code the values into the add_option statement, but if you make a small plug-in with a page where you can edit them, you’d possibly save yourself time and trouble in the future if you ever need to update the defaults.
Let me know if you need some help implementing this, I’ll need to take a look at your metabox code to help, though.
Try using advanced-custom-fields plugin.
advanced custom fields, you can create custom fields and assign some conditions for displaying the particular custom fields for specific post type or any other condition.
You can use multiple types of custom fields as:
tags)
You can find the documentation here.
To do this without a plugin, as you requested you should read this article on smashing magazine, it offers a complete guide to custom fields.
It may seem like a lot of work, but its quite easy. And if you get the hang of it, it can be a powerful tool to make your WordPress backend user friendly.
For instance you can also add custom fields to attachments.
use
add_meta_box();
it allows you to add meta boxes to the administrative interfacehttp://codex.wordpress.org/Function_Reference/add_meta_box