WordPress the_meta() Function

Beginner
6 min read
Updated: Nov 2026
3 examples
Prints custom fields

Definition

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.

Syntax

A few ways to call the_meta().

WordPress
<?php
the_meta();
CallWhat 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.

Full declaration
WordPress
the_meta(): void

Parameters

ParameterDescription
(none)This function takes no parameters.

Return Value

Return ValueDescription
voidNothing is returned. The list is printed, or nothing if there are no public fields.

WordPress Examples

Three short examples. Each one shows the code and what it prints.

Example 1 — Print all custom fields

Show every public custom field of the post.

WordPress
<?php the_meta(); ?>

How It Works

  1. Each custom field becomes one li.
  2. The name is shown with a colon.
  3. Fields that start with _ are not printed.

Example 2 — Print one field safely

Use get_post_meta() to print one field.

WordPress
<?php
$mood = get_post_meta( get_the_ID(), 'mood', true );
if ( $mood ) {
  echo '<p>Mood: ' . esc_html( $mood ) . '</p>';
}

How It Works

  1. The third argument true returns one value.
  2. The if skips posts that have no value.
  3. esc_html() makes the output safe.

Example 3 — Loop over all fields

Use get_post_custom() to build your own list.

WordPress
<?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";
}

How It Works

  1. get_post_custom() returns all fields as an array.
  2. The continue skips hidden fields that start with _.
  3. You control the HTML, and values are escaped.

Frequently Asked Questions

It prints the public custom fields of the current post as an unordered list.
Fields whose names start with an underscore are treated as private and are hidden.
No. For safe output, use get_post_meta() with esc_html().
Use get_post_meta( get_the_ID(), 'key', true ).
In the post editor, turn on Custom Fields in the screen options, then add a name and a value.

Browse all post functions

Open the functions index for simple guides with examples and FAQs.

Post Functions Index →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

14 people found this page helpful