Example 1 — Print all custom fields
Show every public custom field of the post.
<?php the_meta(); ?> How It Works
- Each custom field becomes one
li. - The name is shown with a colon.
- Fields that start with
_are not printed.

In WordPress, the_meta() prints the custom fields of the current post as an unordered list. Custom fields are extra key and value pairs you add to a post.
It is a quick way to show them all. For full control, use get_post_meta() instead.
A few ways to call the_meta().
<?php
the_meta(); | Call | What it does |
|---|---|
the_meta() | Print all public custom fields. |
get_post_meta( $id, 'mood', true ) | Return one custom field value. |
get_post_custom( $id ) | Return all custom fields as an array. |
It prints a list and takes no arguments. Fields whose names start with an underscore _ are hidden.
the_meta(): void | Parameter | Description |
|---|---|
(none) | This function takes no parameters. |
| Return Value | Description |
|---|---|
| void | Nothing is returned. The list is printed, or nothing if there are no public fields. |
Three short examples. Each one shows the code and what it prints.
Show every public custom field of the post.
<?php the_meta(); ?> li._ are not printed.Use get_post_meta() to print one field.
<?php
$mood = get_post_meta( get_the_ID(), 'mood', true );
if ( $mood ) {
echo '<p>Mood: ' . esc_html( $mood ) . '</p>';
} true returns one value.if skips posts that have no value.esc_html() makes the output safe.Use get_post_custom() to build your own list.
<?php
$fields = get_post_custom();
foreach ( $fields as $key => $values ) {
if ( substr( $key, 0, 1 ) === '_' ) {
continue;
}
echo esc_html( $key ) . ': ' . esc_html( $values[0] ) . "\n";
} get_post_custom() returns all fields as an array.continue skips hidden fields that start with _.Open the functions index for simple guides with examples and FAQs.
14 people found this page helpful