![WordPress Logo WordPress Logo](https://i0.wp.com/2.bp.blogspot.com/_nvQC_nchP4o/TTchIe4G3_I/AAAAAAAALhw/yXyAK-VexXY/s1600/WordPress.jpg?resize=150%2C150)
WordPress provides authors with a way to add additional information to a post/page by using custom fields. Custom Fields can be anything from defining an author of a post to setting an expiry date.
In this post, I will show how can add, delete and edit custom fields in WordPress.
Add Custom Field to a WordPress Post/Page
It’s quite easy to add custom fields to a post/page, and you might have already done it many a times.
To do so, simply find the “Custom Fields” meta box, and add a unique field name and any value you want. For example, here I will add a new custom field value of “author” to a post, which has “SumTips Admin” as it’s value.
![Add Custom Field Add Custom Field](https://i0.wp.com/lh4.googleusercontent.com/-G0sKg2W4o5I/TXYdtPzRooI/AAAAAAAALqc/E-D0vtgccB0/s1600/Add-Custom-Field-WordPress.png?resize=532%2C217&ssl=1)
Delete Custom Field Value of a WordPress Post/Page
There are three ways to delete a Custom field from WordPress, and all are shown here.
- Delete Custom Field from all posts: Remove the custom field you want to delete by editing all posts containing it. Once there are no more posts containing a custom field, it is automatically deleted from the database.
- From the database: Custom Field values can be deleted directly from the database. It’s a bit tricky, so make sure you backup the database before following this method.
- Using a plugin: This method is the safest and fastest of all.
Delete custom field from database:
Login to phpmyadmin, and click on wp_postmeta in the left sidebar. Next go to Structure view, select meta_key and click on browse.
![Delete Custom Field 1 Delete Custom Field 1](https://i0.wp.com/lh5.googleusercontent.com/-qxMulRowDg4/TXYgAOWSlGI/AAAAAAAALqk/iCMLlgH8CV4/s1600/Delete-Custom-Field-WordPress-1.png?resize=532%2C191&ssl=1)
Now you can see the earlier created author custom field.
![Delete Custom Field 2 Delete Custom Field 2](https://i0.wp.com/lh6.googleusercontent.com/-bcPCavd886w/TXYhZnXFPPI/AAAAAAAALqs/oRXbWgoTbsE/s1600/Delete-Custom-Field-WordPress-2.png?resize=272%2C85&ssl=1)
However you cannot delete the value here.
So, now click on the Search tab, enter author
in the meta_key field and click on “Go.”
![Delete Custom Field 3 Delete Custom Field 3](https://i0.wp.com/lh4.googleusercontent.com/-6q0OC9ClvCA/TXYiQp___OI/AAAAAAAALq0/ZSVTMSEepfI/s1600/Delete-Custom-Field-WordPress-3.png?resize=532%2C191&ssl=1)
This will give you a list of all the post which has author
as a custom field.
![Delete Custom Field 4 Delete Custom Field 4](https://i0.wp.com/lh6.googleusercontent.com/-CRAM83gB6iI/TXYiP6_oNwI/AAAAAAAALqw/QnslOGyKbaE/s1600/Delete-Custom-Field-WordPress-4.png?resize=403%2C78&ssl=1)
Here select all posts and click on drop to delete the custom field. Another option is to, select only those post from which you want to remove a particular field from and drop them.
Delete custom field using plugin:
An easier way is to use a plugin called Delete Custom.
![Delete Custom Delete Custom](https://i0.wp.com/lh5.googleusercontent.com/-McyA9E7FJgc/TXYjAR_xBdI/AAAAAAAALq4/mbWa2d03_X0/s1600/Delete-Custom-Field-WordPress-5.png?resize=356%2C162&ssl=1)
It gives you a simple interface to select and delete a Custom Field from a drop-down list.
Download: Custom Delete
Edit Custom Field of a WordPress Post/Page
To modify custom fields, follow the steps mentioned earlier, but instead of deleting this time click on “Change.”
![Edit Custom Field Edit Custom Field](https://i0.wp.com/lh5.googleusercontent.com/-knPasI2e-ao/TXYkD1BHhFI/AAAAAAAALrA/l1Qfy64bSxE/s1600/Modify-Custom-Field-WordPress-1.png?resize=403%2C78&ssl=1)
That will bring you to a page as below:
![Edit Custom Field 2 Edit Custom Field 2](https://i0.wp.com/lh4.googleusercontent.com/-SEmMPvhfZiw/TXYkEocv5zI/AAAAAAAALrE/zm8HMWNwoJg/s1600/Modify-Custom-Field-WordPress-2.png?resize=532%2C217&ssl=1)
Here change the value to anything you want and save it.
Hide Custom Field Metabox in WordPress Post/Page Edit Page
If you don’t use or don’t want the Custom Field Metabox, it can be easily removed by adding the following code to your functions.php
file.
function remove_custom_meta_boxes() { remove_meta_box('postcustom','post','normal'); remove_meta_box('postcustom','page','normal'); } add_action('admin_init','hide_custom_meta_boxes');
Remove “post” or “page” line to keep the box in either.
Automatically Add a Specific Custom Field to all New WordPress Post/Page
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); } }
Replace the field-name
and custom value
with your Custom Field Name, and Value. via WPCanyon
2 thoughts on “Add, Delete and Edit Custom Fields in WordPress”
Very useful for me ,thanks
Thanks a lot for a very important post!
you helped me to soled an issue that i had for a very very long time 🙂
Thanks,
Pinto.