W3cubDocs

/WordPress

has_meta( int $post_id ): array[]

Returns meta data for the given post ID.

Parameters

$post_idintrequired
A post ID.

Return

array[] Array of meta data arrays for the given post ID.
  • ...$0 array
    Associative array of meta data.
    • meta_key string
      Meta key.
    • meta_value mixed
      Meta value.
    • meta_id string
      Meta ID as a numeric string.
    • post_id string
      Post ID as a numeric string.

    Source

    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
    	);
    }
    

    Changelog

    Version Description
    1.2.0 Introduced.

    User Contributed Notes

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

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/has_meta