Add Custom Status or Notes to a Post without a Plugin

Think of yourself as a Blogger on the move. You are traveling around the world, sometimes you are at Berlin, and then you move to Paris, yet again to New York.

Wordpress LogoHow cool it would be to add a note to each post that says where you wrote that from? Or maybe you might want to show off your mood, in the mySpace style or insert answers, “What’s on your mind?” or “What are you doing?” with every post.

This can be done using Custom Fields.

Dissection of get_post_meta();

We will use get_post_meta($post_id, $key, $single); for our purpose. It’s a function that’s used to fetch the post meta data.

The code for our use will be:

get_post_meta($post->ID, "note", true);

The post id is the id of the post. It can be any number and the data from the meta of the corresponding post will be used.

In our case, it’s the post that calls the function, use $post->ID. ‘note’ would act as the Custom Field KEY. You can change it to anything you like, and your custom field KEY would be that one.

Insert the following code into any of your post page of your theme file, either single.php or index.php (for StudioPress themes).


< ?php if( get_post_meta($post->ID, "note", true) ): ? >

Posted From: < ?php echo get_post_meta($post->ID, "note", true); ? >

< ?php endif; ? >

The ‘if’ conditions would check if the custom field exists, if it doesn’t exist, nothing will be displayed.

Custom Field for Note

Custom Field for Note

Custom Notes Implemented with some styling on Local Server

Custom Notes Implemented with some styling on Local Server

Have fun! 🙂

Hey! Thanks for reading. If you found it useful, please share it with your friends as well. They will thank you for it.

Divi WordPress Theme - My Review

Divi WordPress Theme
Divi is a WordPress theme that web designers do not want you to know. It comes with a drag-and-drop theme builder. You can build beautiful looking unique websites without touching a line of code. Just choose from one of the many pre-made layouts, or pick elements and arrange them any way you like.

Divi is every WordPress developer's wet dream. Surprise your clients with neat responsive websites and have fun building them.

Divi comes from Elegant Themes. If you enjoy building websites, you *need* an Elegant Themes membership. 87 beautiful themes and 5 plugins for the cost of less than a candy-bar each!


Note: I am an avid user of Divi myself and this is a honest review. I wouldn't recommend something that I do not personally find amazing.

16 Comments.

  1. Atin Gupta says:

    That’s nice, I never thought of this before!

  2. Alok says:

    Woow this is amazing trick to show your mood.
    Thanks Arun. 🙂

  3. Amal Roy says:

    Great Find Dude.

  4. Binny V A says:

    I see you are taking up my baton ;-). Waiting for more stuff like this.

  5. poch says:

    I hope this great idea works for me Arun. Thanks.

  6. iWrite2Know says:

    I think this feature will give a big boost to travel blogs and Bloggers who are always on the move. The readers will get hooked on to the blogs to find out the next destination. Amusing!

  7. Nihar says:

    Great tip Arun.

  8. Vince says:

    Say my “KEY” is “worked hours” and the value a number, would I be able to add them up based on categories or tags later?
    I’m thinking on applying this for posting tasks on a private blog, each could have a custom field “status” (filed, in progress, on hold , completed) and on completion later on add up a new custom field to the posts for worked hours. But a worked hours “counter” will be nescesary.
    What do you think?

    • The status part could work, the counter, someone would have to manually add that to the custom field. Or better you could use the modified times to get the overall time spent on the post. btw, keys cannot have spaces in between

Leave a Reply

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

*

Share With Friends