the_meta()WP 1.2.0

Deprecated from version 6.0.2. It is no longer supported and can be removed in future releases. Use get_post_meta() to retrieve post meta and render manually instead.

Display list of post custom fields.

1 time — 0.001464 sec (very slow) | 50000 times — 2.87 sec (fast) | PHP 7.1.2, WP 4.7.3
Hooks from the function

Return

null. Nothing (null).

Usage

the_meta();

Examples

0

#1 Display the metadata of the post

To do this, place the following code in the file single.php after the template tag (function) the_content()

<p>Meta information about the current post:</p>
<?php the_meta(); ?>

This code will output the following

<p>Meta information about the current post:</p>
<ul class='post-meta'>
	<li><span class='post-meta-key'>key name:</span> field value</li>
</ul>

Changelog

Since 1.2.0 Introduced.
Deprecated since 6.0.2 Use get_post_meta() to retrieve post meta and render manually.

the_meta() code WP 6.4.3

function the_meta() {
	_deprecated_function( __FUNCTION__, '6.0.2', 'get_post_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. */
				esc_html( sprintf( _x( '%s:', 'Post custom field name' ), $key ) ),
				esc_html( $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";
		}
	}
}