ShoutMeLoud – Shouters Who Inspire

Superlinks
≡ Menu
≡ Menu

How to Use Custom Fields in WordPress Blog

rainmaker
How to Use Custom Fields in WordPress Blog

For me, wordpress is the best CMS I ever came across. Its easy to use, flexible and can be modified in any way. The wordpress has gained more popularity because of its custom fields. Before WordPress custom fields were introduced WP was just a blogging platform. After the introduction of custom fields, it has been widely used as Content Management system. So how to use custom fields? Let me first give you little introduction to custom fields.

What are WordPress Custom Fields?

Custom Field in WordPress are additional data you can add to your posts and pages. For a good start you can check “Custom Fields”. It’s a basic tutorial but will give you little idea about custom fields. The page doesn’t contain much use of custom fields that’s why many people don’t know what to do with it, but the truth is, you can do much anything you want with custom fields.

The custom fields input is located on “Add Post” or “Add Page” page below your editor. If you don’t see it, click the “Screen Options” and then check the “Custom Fields” box in the Top-Right corner.

There are two different things you can input into a custom field — “Key” and “Value.” It doesn’t get much simpler than that.

custom fields box

What is a Key and Value?

The Key is the name of the custom field and the Value is simply the value you want to give to that name.

For a live example, let’s say you run a blog about medicines.You have categories set up for each post (Ayurvedic, Allopathic, etc.) and you tag your post with manufacturer’s name. But you want to display the Mfg. Date, Expiry Date and Price of the medicine. The best way to add these extra data is using custom fields.

So first click on “Enter New” and you’ll see empty Name and Value. Add Mfg_Date in name field and the value, lets say “May 2011″ and then click Add Custom Field. Now you have successfully created custom field named Mfg. Date and in future when you create a new post and want to add Mfg. Date, you’ll just have to select it from drop-down and add your value for that post.

enter new

Now the question is how to display it? It’s very simple too. In the single.php file of your theme add the following code.

<?php echo get_post_meta($post->ID, “Mfg_Date”, true); ?>

(You might want to display it in ordered list or a paragraph. You can use HTML in the value of the field.)

You can display posts with specific custom field. lets go to our Medicine. Now what if i want to display list of medicine with Mfg. Date? This can be achieved by the following code.

query_posts(‘meta_key=Mfg_Date’);

If we want to display medicine manufactured in August 2011, we could do something with the following code:

query_posts(‘meta_key=Mfg_Date&meta_value=August 2011′);

This is general tutorial, now it depends on your imagination, how you use it. Now, here is an interesting bit for everyone, who is running WordPress blog for long time. How many times, you have changed your theme and use WordPress custom field to Add images or any other element? How many times you have added a new plugin like Popularity count, which again adds new custom field. Have you imagined what happens to custom field, when you change your theme or remove plugins?

In most of the cases, those custom field remains a part of your Database and you can use plugins like Clean options or follow Harsh guide on delete WordPress custom field value manually.

Do let me know if you have more to share on WordPress custom fields and how to use it effectively?

This is a guest post by Nikhil from The Dripple. If you would like to write for ShoutMeLoud, check our guest posting guidelines.

  • Author Bio

  • Latest Post

Article by Nikhil Phirke

Nikhil has written 1 articles.

If you like This post, you can follow ShoutMeLoud on Twitter. Subscribe to ShoutMeLoud feed via RSS or EMAIL to receive instant updates.


    { 3 comments… add one }

    • Earlyman

      Very useful post. I do use custom fields, it is really useful when you are, for example, often comparing different products and want to keep track of the reviews in a form that makes it easier for the user to access your content straight away (for example, through a chart) and subsequently dig deeper in the article/review itself. It also sounds more complicated than it actually is, once you have gotten the hold of it.

      Reply
    • akhilendra

      honestly i never used it but after going through post, it’s more like than ever that i will go through it once again to use, sounds interesting.

      Reply

    Leave a Comment