Truemag

  • Categories
    • Tips And Tricks
    • Internet
    • PHP
    • Javascript
    • CSharp
    • SQL Server
    • Linux
  • Lastest Videos
  • Our Demos
  • About
  • Contact
  • Home
  • Write With Us
  • Job Request
Home Tips And Tricks Add And Get Custom Field In WordPress

Add And Get Custom Field In WordPress

In WordPress, Custom Fields are known as meta-data which are some extra information for a post. It’s powerful feature in WordPress so everyone should know if you decided to use WordPress for your business.

Today, I will show how to add a custom field to a post and display it somewhere in your post detail page. And if you would like to get all custom fields for a particular post, we already have a solution for that.

1. Adding a Custom Field

1. When add/edit a post, scroll down to the area titled Custom Fields. If for some reason, your Custom Fields panel is hidden, read this post: http://4rapiddev.com/problem-issue-error/excerpt-box-disappeared-on-wordpress-new-version/ will help you how to enable it again.

2. To create a custom field named “featured_image” has value “http://4rapiddev.com/wp-content/uploads/2011/03/Facebook-Like-Button-On-Wordpress.jpg”, simply enter the text “featured_image” in the text field titled Name and enter the text “http://4rapiddev.com/wp-content/uploads/2011/03/Facebook-Like-Button-On-Wordpress.jpg” in the text field titled Value

Wordpress Add Custom Field

Wordpress Add Custom Field

3. Click Add Custom Field button to save the extra information for the post.

2. Displaying Custom Field

After create the custom field, it’s time to display it on your post. To display it on your post detail page, you need to know the ID of your current page with:

$post_id = $post->ID;

$post_id = $post->ID;

Then use get_post_meta() function to get the value of a particular custom field with a specified key. In this case, you need to get the value of custom field named featured_image, so use this script:

$featured_image = get_post_meta($post_id, "featured_image", true);

$featured_image = get_post_meta($post_id, "featured_image", true);

For more detail about the get_post_meta() function, go to this page.

Mar 30, 2011Hoan Huynh
Place Facebook Like Button On WordPressLG Optimus 2X Key Specifications
You Might Also Like:
  • WordPress Get All Custom Fields
  • Show Error Message On WordPress Custom Login Template Page
  • Create Custom Update Profile Page For WordPress Users
  • Share Page On Facebook With Thumbnail Featured Image
  • Add WordPress Login Form On Sidebar Or Custom Page
  • How To Change Default Home Page Of WordPress
  • WordPress Check If Post Is In Category
  • Keep Posting When You’re On Vacation With WordPress Post TimeStamp
  • Excerpt box disappeared on WordPress New Version
  • How to create new custom menu item in your wordpress back end?
Hoan Huynh

Hoan Huynh is the founder and head of 4rapiddev.com. Reach him at [email protected]

11 years ago Tips And TricksCustom Field, get_post_meta, Wordpress241
0
GooglePlus
0
Facebook
0
Twitter
0
Digg
0
Delicious
0
Stumbleupon
0
Linkedin
0
Pinterest
Most Viewed
PHP Download Image Or File From URL
24,554 views
Notepad Plus Plus Compare Plugin
How To Install Compare Text Plugin In Notepad Plus Plus
21,892 views
Microsoft SQL Server 2008 Attach Remove Log
Delete, Shrink, Eliminate Transaction Log .LDF File
17,745 views
JQuery Allow only numeric characters or only alphabet characters in textbox
15,069 views
C# Read Json From URL And Parse/Deserialize Json
11,802 views
4 Rapid Development is a central page that is targeted at newbie and professional programmers, database administrators, system admin, web masters and bloggers.
Recent Posts
  • Things to Learn about Installingderm Loan Type S
  • Online Photo Editor – Free Photoediting Software
  • A Guide to Finding the Best Paper Sellers
  • Photoediting in Home Isn’t Hard to Do!

  • Free Photo Editor Online
Categories
  • CSharp (45)
  • Facebook Graph API (19)
  • Google API (7)
  • Internet (87)
  • iPhone XCode (8)
  • Javascript (35)
  • Linux (27)
  • MySQL (16)
  • PHP (84)
  • Problem Issue Error (29)
  • Resources (32)
  • SQL Server (25)
  • Timeline (5)
  • Tips And Tricks (141)
  • Uncategorized (647)
Recommended
  • Custom Software Development Company
  • Online Useful Tools
  • Premium Themes
  • VPS
2014 © 4 Rapid Development