On this page
get_post_meta( int $post_id, string $key = '', bool $single = false ): mixed
Retrieves a post meta field for the given post ID.
Parameters
$post_idint Required-
Post ID.
$keystring Optional-
The meta key to retrieve. By default, returns data for all keys.
Default:
'' $singlebool Optional-
Whether to return a single value.
This parameter has no effect if$keyis not specified.
Default:
false
Return
mixed An array of values if $single is false.
The value of the meta field if $single is true.
False for an invalid $post_id (non-numeric, zero, or negative value).
An empty string if a valid but non-existing post ID is passed.
More Information
- Please note that if a db collation is case insensitive (has with suffix _ci) then update_post_meta and delete_post_meta and get_posts() will update/delete/query the meta records with keys that are upper or lower case. However get_post_meta will apparently be case sensitive due to WordPress caching. See https://core.trac.wordpress.org/ticket/18210 for more info. Be careful not to mix upper and lowercase.
- Uses: get_metadata() to retrieve the metadata.
Source
File: wp-includes/post.php. View all references
function get_post_meta( $post_id, $key = '', $single = false ) {
return get_metadata( 'post', $post_id, $key, $single );
}
Related
Uses
| Uses | Description |
|---|---|
| get_metadata() wp-includes/meta.php | Retrieves the value of a metadata field for the specified object type and ID. |
Used By
| Used By | Description |
|---|---|
| update_menu_item_cache() wp-includes/nav-menu.php | Updates post and term caches for all linked objects for a list of menu items. |
| _build_block_template_result_from_post() wp-includes/block-template-utils.php | Builds a unified template object based a post Object. |
| get_media_states() wp-admin/includes/template.php | Retrieves an array of media states from an attachment. |
| WP_REST_Attachments_Controller::edit_media_item() wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php | Applies edits to a media item and creates a new attachment record. |
| get_post_states() wp-admin/includes/template.php | Retrieves an array of post states from a post. |
| WP_User_Request::__construct() wp-includes/class-wp-user-request.php | Constructor. |
| _wp_privacy_send_request_confirmation_notification() wp-includes/user.php | Notifies the site administrator via email when a request is confirmed. |
| _wp_privacy_send_erasure_fulfillment_notification() wp-includes/user.php | Notifies the user when their erasure request is fulfilled. |
| wp_check_for_changed_dates() wp-includes/post.php | Checks for changed dates for published post objects and save the old date. |
| WP_Privacy_Policy_Content::get_suggested_policy_text() wp-admin/includes/class-wp-privacy-policy-content.php | Check for updated, added or removed privacy policy information from plugins. |
| WP_Privacy_Policy_Content::text_change_check() wp-admin/includes/class-wp-privacy-policy-content.php | Quick check if any privacy info has changed. |
| WP_Privacy_Policy_Content::_policy_page_updated() wp-admin/includes/class-wp-privacy-policy-content.php | Update the cached policy info when the policy page is updated. |
| wp_privacy_process_personal_data_export_page() wp-admin/includes/privacy-tools.php | Intercept personal data exporter page Ajax responses in order to assemble the personal data export file. |
| wp_privacy_generate_personal_data_export_file() wp-admin/includes/privacy-tools.php | Generate the personal data export file. |
| wp_privacy_send_personal_data_export_email() wp-admin/includes/privacy-tools.php | Send an email to the user with a link to the personal data export file |
| WP_Customize_Manager::set_changeset_lock() wp-includes/class-wp-customize-manager.php | Marks the changeset post as being currently edited by the current user. |
| WP_Customize_Manager::refresh_changeset_lock() wp-includes/class-wp-customize-manager.php | Refreshes changeset lock with the current time if current user edited the changeset before. |
| WP_Customize_Manager::import_theme_starter_content() wp-includes/class-wp-customize-manager.php | Imports theme starter content into the customized state. |
| WP_REST_Attachments_Controller::prepare_item_for_response() wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php | Prepares a single attachment output for response. |
| WP_Customize_Nav_Menus::save_nav_menus_created_posts() wp-includes/class-wp-customize-nav-menus.php | Publishes the auto-draft posts that were created for nav menu items. |
| get_custom_logo() wp-includes/general-template.php | Returns a custom logo, linked to home unless the theme supports removing the link on the home page. |
| get_header_image_tag() wp-includes/theme.php | Creates image tag markup for a custom header image. |
| wp_ajax_crop_image() wp-admin/includes/ajax-actions.php | Ajax handler for cropping an image. |
| wp_restore_image() wp-admin/includes/image-edit.php | Restores the metadata for a given attachment. |
| wp_save_image() wp-admin/includes/image-edit.php | Saves image to post, along with enqueued changes in |
| wp_image_editor() wp-admin/includes/image-edit.php | Loads the WP image-editing interface. |
| edit_form_image_editor() wp-admin/includes/media.php | Displays the image and editor in the post editor |
| get_attachment_fields_to_edit() wp-admin/includes/media.php | Retrieves the attachment fields to edit form fields. |
| media_upload_form_handler() wp-admin/includes/media.php | Handles form submissions for the legacy media uploader. |
| wp_check_post_lock() wp-admin/includes/post.php | Determines whether the post is currently being edited by another user. |
| edit_post() wp-admin/includes/post.php | Updates an existing post with values provided in |
| wp_ajax_wp_fullscreen_save_post() wp-admin/includes/ajax-actions.php | Ajax handler for saving posts from the fullscreen editor. |
| wp_ajax_save_attachment() wp-admin/includes/ajax-actions.php | Ajax handler for updating attachment attributes. |
| post_thumbnail_meta_box() wp-admin/includes/meta-boxes.php | Displays post thumbnail meta box. |
| post_submit_meta_box() wp-admin/includes/meta-boxes.php | Displays post submit form fields. |
| Custom_Image_Header::get_uploaded_header_images() wp-admin/includes/class-custom-image-header.php | Gets the previously uploaded header images. |
| map_meta_cap() wp-includes/capabilities.php | Maps a capability to the primitive capabilities required of the given user to satisfy the capability being checked. |
| get_uploaded_header_images() wp-includes/theme.php | Gets the header images uploaded for the active theme. |
| WP_Embed::shortcode() wp-includes/class-wp-embed.php | The do_shortcode() callback function. |
| get_post_thumbnail_id() wp-includes/post-thumbnail-template.php | Retrieves the post thumbnail ID. |
| _wp_menu_item_classes_by_context() wp-includes/nav-menu-template.php | Adds the class property classes for the current context, if applicable. |
| get_page_template_slug() wp-includes/post-template.php | Gets the specific template filename for a given post. |
| wp_maybe_generate_attachment_metadata() wp-includes/media.php | Maybe attempts to generate attachment metadata, if missing. |
| wp_prepare_attachment_for_js() wp-includes/media.php | Prepares an attachment post object for JS, where it is expected to be JSON-encoded and fit into an Attachment model. |
| wp_enqueue_media() wp-includes/media.php | Enqueues all scripts, styles, settings, and templates necessary to use all media JS APIs. |
| wp_get_attachment_image() wp-includes/media.php | Gets an HTML img element representing an image attachment. |
| WP_Post::__get() wp-includes/class-wp-post.php | Getter. |
| wp_check_for_changed_slugs() wp-includes/post.php | Checks for changed slugs for published post objects and save the old slug. |
| wp_delete_attachment() wp-includes/post.php | Trashes or deletes an attachment. |
| wp_get_attachment_metadata() wp-includes/post.php | Retrieves attachment metadata for attachment ID. |
| wp_get_attachment_url() wp-includes/post.php | Retrieves the URL for an attachment. |
| wp_untrash_post_comments() wp-includes/post.php | Restores comments for a post from the Trash. |
| wp_insert_post() wp-includes/post.php | Inserts or update a post. |
| wp_untrash_post() wp-includes/post.php | Restores a post from the Trash. |
| get_post_custom() wp-includes/post.php | Retrieves post meta fields, based on post ID. |
| get_post_status() wp-includes/post.php | Retrieves the post status based on the post ID. |
| get_attached_file() wp-includes/post.php | Retrieves attached file path based on attachment ID. |
| get_the_modified_author() wp-includes/author-template.php | Retrieves the author who last edited the current post. |
| wp_get_associated_nav_menu_items() wp-includes/nav-menu.php | Returns the menu items associated with a particular object. |
| wp_setup_nav_menu_item() wp-includes/nav-menu.php | Decorates a menu item object with the shared navigation menu item properties. |
| wp_update_nav_menu_item() wp-includes/nav-menu.php | Saves the properties of a menu item or create a new one. |
| wp_xmlrpc_server::add_enclosure_if_new() wp-includes/class-wp-xmlrpc-server.php | Adds an enclosure to a post if it’s new. |
| wp_xmlrpc_server::_prepare_post() wp-includes/class-wp-xmlrpc-server.php | Prepares post data for return in an XML-RPC object. |
Changelog
| Version | Description |
|---|---|
| 1.5.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_post_meta