the_meta()

Display a list of post custom fields.


More Information More Information

This is a simple built-in function for displaying custom fields for the current post, known as the “post-meta” (stored in the wp_postmeta table). It formats the data into an unordered list (see output below).

It must be used from within The Loop or in a theme file that handles data from a single post (e.g. single.php). the_meta() will ignore meta_keys (i.e. field names) that begin with an underscore.

For more information on this tag, see Custom Fields.


Top ↑

Source Source

File: wp-includes/post-template.php

function the_meta() {
	$keys = get_post_custom_keys();
	if ( $keys ) {
		$li_html = '';
		foreach ( (array) $keys as $key ) {
			$keyt = trim( $key );
			if ( is_protected_meta( $keyt, 'post' ) ) {
				continue;
			}

			$values = array_map( 'trim', get_post_custom_values( $key ) );
			$value  = implode( ', ', $values );

			$html = sprintf(
				"<li><span class='post-meta-key'>%s</span> %s</li>\n",
				/* translators: %s: Post custom field name. */
				sprintf( _x( '%s:', 'Post custom field name' ), $key ),
				$value
			);

			/**
			 * Filters the HTML output of the li element in the post custom fields list.
			 *
			 * @since 2.2.0
			 *
			 * @param string $html  The HTML output for the li element.
			 * @param string $key   Meta key.
			 * @param string $value Meta value.
			 */
			$li_html .= apply_filters( 'the_meta_key', $html, $key, $value );
		}

		if ( $li_html ) {
			echo "<ul class='post-meta'>\n{$li_html}</ul>\n";
		}
	}
}


Top ↑

Changelog Changelog

Changelog
Version Description
1.2.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 2 content
    Contributed by Jb Audras

    Since revision 41583, the_meta() allow translators to manage spaces before the colon character.

    Default output:

    <ul class="post-meta">
        <li><span class='post-meta-key'>Your first meta key:</span> one or several values separated by commas</li>
        …
        <li><span class='post-meta-key'>Your second meta key:</span> one or several values separated by commas</li>
        <li><span class='post-meta-key'>Your third meta key:</span> one or several values separated by commas</li>
    </ul>
    

    French output:

    <ul class="post-meta">
    	<li><span class='post-meta-key'>Your first meta key :</span> one or several values separated by commas</li>
    	…
    	<li><span class='post-meta-key'>Your second meta key :</span> one or several values separated by commas</li>
    	<li><span class='post-meta-key'>Your third meta key :</span> one or several values separated by commas</li>
    </ul>
    

    There is a non breaking space character before the colon character. Each Locale can handle it differently.

You must log in before being able to contribute a note or feedback.