WordPress at a glance

the_meta() WP 1.0

Display list of post custom fields.

Works based on: get_post_custom_keys()
✈ 1 time = 0.001464s = very slow | 50000 times = 2.87s = fast | PHP 7.1.2, WP 4.7.3
Hooks from the function
Return

Null. Nothing.

Usage

the_meta();

Changelog

Since 1.2.0 Introduced.

Code of the meta: wp-includes/post-template.php WP 5.2.2

<?php
function the_meta() {
	if ( $keys = get_post_custom_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";
		}
	}
}

Related Functions

From tag: Metadatas (any)

More from Template Tags: Posts, Pages, ...

No comments
    Hello, !     Log In . Register