has_meta()WP 1.2.0

Returns meta data for the given post ID.

No Hooks.

Returns

Array[]. Array of meta data arrays for the given post ID.

Usage

has_meta( $post_id );
$post_id(int) (required)
A post ID.

Notes

  • Global. wpdb. $wpdb WordPress database abstraction object.

Changelog

Since 1.2.0 Introduced.

has_meta() code WP 6.8.1

function has_meta( $post_id ) {
	global $wpdb;

	return $wpdb->get_results(
		$wpdb->prepare(
			"SELECT meta_key, meta_value, meta_id, post_id
			FROM $wpdb->postmeta WHERE post_id = %d
			ORDER BY meta_key,meta_id",
			$post_id
		),
		ARRAY_A
	);
}