Categories
Wordpress Wordpress Loop

Displaying WordPress Custom Fields in loop | Part 3 of Custom Field Tutorial

Introduction –> Adding Custom Fields –> Displaying Custom fields  –> Doing through Plugin


This is the third part of the tutorial and within next ten minuted you will be able to display custom fields in your post. We need to add a small piece of code in the wordpress loop. If you are a developer you must be knowing about the loop, and if you are not, try to find out wordpress loop in content.php or single.php or content-single.php. In most of the cases loop is present in one of the above mentioned files. So let us check the  code needed to display the fields which we added in last part.

 

<?php echo get_post_meta($post->ID,'key',true); ?>

We need to change the key to key name which he has entered while creating the field. The above code will display the value of the custom field added and not the key or Name. So I am doing a proper formatting to display the key name as well as the value.

 

<?php echo "Theme Code:".get_post_meta($post->ID,'ThemeCode',true). "<br>"; ?>

One need to repeat this code everytime he wants to display different fields. Below is the image of code we wrote to add the fields we created in previous part of this tutorial.

 

Below is the output on Post, after adding the Coding to display the custom fields.

 

Seems Nice na !!. You now know how to add custom fields to a wordpress blog. So if you need to add the same fields to different post, you dont need to do any step again. One just need to add new post and just add the field values. Below is an image describing the same.

 

In the next part of tutorial we are going to do this all in a easy way. We will be doing the stuff through a plugin. Well there are several free and premium plugins available, but we have chosen Wp-Types to do all these stuff via plugin. Details are provided in next part.

Introduction –> Adding Custom Fields –> Displaying Custom fields  –> Doing through Plugin


 

 

By Anirudh Babbar

A website developer, loves #wordpress #drupal #php. Love posting about wordpress, php, bootstrap and SEO. Also provide online/offline training on wordpress, drupal, php and SEO. I am available on Twitter @ anibabbar , Skype @anibabbar , gmail @anibabbar !! facebook @thinkncode.com