Have you ever heard about custom fields or custom meta boxes in WordPress? You probably already use them without realizing it!
Custom fields are one of WordPress’s most powerful features. They let you store extra information (called post meta) about your posts, pages, or products; things like prices, ratings, or custom messages.
Many developers get stuck when it comes to retrieving these values in their themes or plugins. In this article, I’ll explain exactly how to use get_post_meta() to get your custom field data and make the most of it in your projects.
Table of Contents
What Are WordPress Post Meta Data?
At its core, post meta (short for metadata) refers to the extra information associated with each post in WordPress. They provide details that aren’t immediately visible on the front end.
A WordPress post meta could be anything, like the price of a WooCommerce product. Or the client of a project for a Portfolio post type. If you used custom fields before, or the plugin Advanced Custom Fields (ACF), those fields’ values are post metadata.
They’re primarily stored in the wp_postmeta table in the database.

How do Post Meta Improve Your Content?
Post meta data are useful in many cases:
- Customization: Using post meta, you can tailor your content to fit your needs. Want to add a book review rating to your posts? Post meta makes it easy.
- Organization: It helps in sorting and filtering content. For example, you can display all posts from a specific author or those with a particular custom field value.
- Dynamic Content: When you mix post meta with plugins or custom code, they can change how you display the content based on its metadata.
If you are also optimizing your site structure, this guide on WordPress tags SEO explains how to use tags in a way that actually helps search engines and readers.
How to get Custom Field Values with get_post_meta?
WordPress offers the get_post_meta function. You can use it on any post type: a post, page, or product. This function uses three parameters:
$post_id: The specific ID of the post.$key: The custom field name, also known as meta key. It is often prefixed with_to indicate hidden post meta.$single(optional): Determines if the custom field value is singular or an array.
Here is a usage example:
// Optionally retrieve the post object if you don't have it already
global $post;
// Get the value of the post meta with name `_my_post_meta_name`
$post_meta_value = get_post_meta( $post->ID, '_my_post_meta_key', true );
// Print the post meta value
printf( "The value of my post meta is %s", $post_meta_value );
Remember, get_post_meta can be used on any custom post type, not just blog articles or pages.
How to Add or Update Post Meta with Code
To add the meta field values to the database, use the add_post_meta function. This function requires four parameters:
$post_id: the post ID. Remember, it can be any post type, not necessarily an actual post.$key: the custom field name.$value: the post meta data value.$single(optional, to avoid duplicate keys): for updating existing custom fields.
Updating WordPress post meta fields works similarly, with update_post_meta function.
How to Update or Add Post Meta in an Existing Post Without Code
Step 1. Access the Post Editor: Navigate to your WordPress dashboard and open the post you want to update.
Step 2. Locate the Custom Fields Metabox: Scroll down below the post editor. If you don’t see the Custom Fields section there, click on Screen Options at the top right of your screen and activate the Custom Fields. If you are using the Block Editor instead, you should go to Preferences (the three dots on top right) > Panels > Custom Fields.

Step 3. Add the Custom Field: In the Custom Fields section, click Enter new to create a new field. Here, you’ll enter a name and value for your custom field. The name is like a label.
It is the $key you’ve seen in the article above. Value is the actual information you’re adding or updating.
- Name: Choose a name that is descriptive and unique to this particular type of information.
- Value: Enter the specific data or note you want to add to your post.
Step 4. Save Your Changes: Once you’ve filled out these fields, click Add Custom Field, and don’t forget to save or update your post.

How to Delete Post Meta in WordPress
Deleting WordPress custom post meta works just like adding or updating. The function to delete custom field values is delete_post_meta(). It needs three parameters:
$post_id: the post ID.$key: the custom field name.$value(optional): the specific value to delete.
To delete post meta fields without code, reach the custom fields section just like when you added them, and delete them.
Level Up Your WordPress Experience
Now that you’re familiar with the concept of WordPress post meta and how to use them, it’s time to experiment. Start by exploring the custom fields feature in your next post. See how it can add depth and functionality to your content.
Remember, the power of WordPress is in its flexibility and customization. Post meta data are a cornerstone of this capability.
I’d love to hear how you plan to use post meta in your WordPress site. Share your ideas or questions in the comments below!


Leave a Comment