Skip to content
GPLWP Guides

How to display custom fields in WordPress

Developer Tools Time About 20 minutes Updated 15 Sep 2026

DEVELOPER TOOLS
The short answer

WordPress stores custom fields as post meta. In a theme template, retrieve a value with get_post_meta() and output it after checking that it exists. For repeated layouts, conditional fields, or non-developers, a view builder is usually quicker.

What you need

  • A WordPress site with at least one saved custom field
  • The exact custom field key
  • Administrator or file-editing access
  • A child theme or code-snippet workflow for PHP changes
The fast route

Let Meta Box Views do it

Twig-based views for Meta Box fields without editing theme files; choose it for dynamic templates and conditional field layouts.

Get Meta Box Views

Sources

  1. developer.wordpress.org /reference/functions/get_post_meta/?utm_source=openai
  2. wordpress.org /support/topic/conditional-display-logic-for-custom-fields/?…

Questions

Does WordPress display custom fields automatically?
No. WordPress stores custom fields as post meta, but your theme or a view tool must output the value on the front end. In a PHP template, use <code>get_post_meta( get_the_ID(), 'field_key', true )</code>, check that the result exists, and escape it for its output context.
Why is my custom field empty in the template?
The usual causes are an incorrect field key, the wrong post ID, a value saved against another post type, or code placed in a template that is not being used. Check the key exactly, including capitalisation, and use WP-CLI with <code>wp post meta list POST_ID</code> if you have command-line access.
How do I display a custom field only when it has a value?
Retrieve the field, compare it with an empty value, and wrap the markup in the condition. For example, use <code>$value = get_post_meta( get_the_ID(), 'subtitle', true );</code> followed by <code>if ( $value !== '' )</code>. Do not add a semicolon immediately after the condition, because that ends the test before the output runs.
How do I display all custom fields for a post?
Call <code>get_post_meta( $post_id )</code> without a key to receive the post's metadata, then loop through the returned key-and-values array. This is mainly useful for debugging or inspection. For production layouts, request known keys individually so internal metadata is not accidentally exposed.
Should I use code or a plugin to display custom fields?
Use code for a small number of stable fields when you control the theme and are comfortable maintaining PHP. Use a view builder when layouts include repeaters, conditions, multiple field types, or frequent editor changes. Meta Box Views is the quicker option when your fields come from Meta Box and you want Twig-based views without editing theme files.