wp-admin/includes/template.php:
get_media_states()
|
Retrieves an array of media states from an attachment.
|
wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php:
WP_REST_Attachments_Controller::edit_media_item()
|
Applies edits to a media item and creates a new attachment record.
|
wp-admin/includes/template.php:
get_post_states()
|
Retrieves an array of post states from a post.
|
wp-includes/class-wp-user-request.php:
WP_User_Request::__construct()
|
Constructor.
|
wp-includes/user.php:
_wp_privacy_send_request_confirmation_notification()
|
Notify the site administrator via email when a request is confirmed.
|
wp-includes/user.php:
_wp_privacy_send_erasure_fulfillment_notification()
|
Notify the user when their erasure request is fulfilled.
|
wp-includes/post.php:
wp_check_for_changed_dates()
|
Check for changed dates for published post objects and save the old date.
|
wp-admin/includes/class-wp-privacy-policy-content.php:
WP_Privacy_Policy_Content::get_suggested_policy_text()
|
Check for updated, added or removed privacy policy information from plugins.
|
wp-admin/includes/class-wp-privacy-policy-content.php:
WP_Privacy_Policy_Content::text_change_check()
|
Quick check if any privacy info has changed.
|
wp-admin/includes/class-wp-privacy-policy-content.php:
WP_Privacy_Policy_Content::_policy_page_updated()
|
Update the cached policy info when the policy page is updated.
|
wp-admin/includes/privacy-tools.php:
wp_privacy_process_personal_data_export_page()
|
Intercept personal data exporter page Ajax responses in order to assemble the personal data export file.
|
wp-admin/includes/privacy-tools.php:
wp_privacy_generate_personal_data_export_file()
|
Generate the personal data export file.
|
wp-admin/includes/privacy-tools.php:
wp_privacy_send_personal_data_export_email()
|
Send an email to the user with a link to the personal data export file
|
wp-includes/class-wp-customize-manager.php:
WP_Customize_Manager::set_changeset_lock()
|
Marks the changeset post as being currently edited by the current user.
|
wp-includes/class-wp-customize-manager.php:
WP_Customize_Manager::refresh_changeset_lock()
|
Refreshes changeset lock with the current time if current user edited the changeset before.
|
wp-includes/class-wp-customize-manager.php:
WP_Customize_Manager::import_theme_starter_content()
|
Import theme starter content into the customized state.
|
wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php:
WP_REST_Attachments_Controller::prepare_item_for_response()
|
Prepares a single attachment output for response.
|
wp-includes/class-wp-customize-nav-menus.php:
WP_Customize_Nav_Menus::save_nav_menus_created_posts()
|
Publish the auto-draft posts that were created for nav menu items.
|
wp-includes/general-template.php:
get_custom_logo()
|
Returns a custom logo, linked to home unless the theme supports removing the link on the home page.
|
wp-includes/theme.php:
get_header_image_tag()
|
Creates image tag markup for a custom header image.
|
wp-admin/includes/ajax-actions.php:
wp_ajax_crop_image()
|
Ajax handler for cropping an image.
|
wp-admin/includes/image-edit.php:
wp_restore_image()
|
Restores the metadata for a given attachment.
|
wp-admin/includes/image-edit.php:
wp_save_image()
|
Saves image to post, along with enqueued changes in $_REQUEST['history'] .
|
wp-admin/includes/image-edit.php:
wp_image_editor()
|
Loads the WP image-editing interface.
|
wp-admin/includes/media.php:
edit_form_image_editor()
|
Displays the image and editor in the post editor
|
wp-admin/includes/media.php:
get_attachment_fields_to_edit()
|
Retrieves the attachment fields to edit form fields.
|
wp-admin/includes/media.php:
media_upload_form_handler()
|
Handles form submissions for the legacy media uploader.
|
wp-admin/includes/post.php:
wp_check_post_lock()
|
Check to see if the post is currently being edited by another user.
|
wp-admin/includes/post.php:
edit_post()
|
Update an existing post with values provided in $_POST.
|
wp-admin/includes/ajax-actions.php:
wp_ajax_wp_fullscreen_save_post()
|
Ajax handler for saving posts from the fullscreen editor.
|
wp-admin/includes/ajax-actions.php:
wp_ajax_save_attachment()
|
Ajax handler for updating attachment attributes.
|
wp-admin/includes/meta-boxes.php:
post_thumbnail_meta_box()
|
Display post thumbnail meta box.
|
wp-admin/includes/meta-boxes.php:
post_submit_meta_box()
|
Displays post submit form fields.
|
wp-admin/includes/class-custom-image-header.php:
Custom_Image_Header::get_uploaded_header_images()
|
Gets the previously uploaded header images.
|
wp-includes/capabilities.php:
map_meta_cap()
|
Maps meta capabilities to primitive capabilities.
|
wp-includes/theme.php:
get_uploaded_header_images()
|
Gets the header images uploaded for the current theme.
|
wp-includes/class-wp-embed.php:
WP_Embed::shortcode()
|
The do_shortcode() callback function.
|
wp-includes/post-thumbnail-template.php:
get_post_thumbnail_id()
|
Retrieve post thumbnail ID.
|
wp-includes/nav-menu-template.php:
_wp_menu_item_classes_by_context()
|
Adds the class property classes for the current context, if applicable.
|
wp-includes/post-template.php:
get_page_template_slug()
|
Get the specific template filename for a given post.
|
wp-includes/media.php:
wp_maybe_generate_attachment_metadata()
|
Maybe attempts to generate attachment metadata, if missing.
|
wp-includes/media.php:
wp_prepare_attachment_for_js()
|
Prepares an attachment post object for JS, where it is expected to be JSON-encoded and fit into an Attachment model.
|
wp-includes/media.php:
wp_enqueue_media()
|
Enqueues all scripts, styles, settings, and templates necessary to use all media JS APIs.
|
wp-includes/media.php:
wp_get_attachment_image()
|
Get an HTML img element representing an image attachment.
|
wp-includes/class-wp-post.php:
WP_Post::__get()
|
Getter.
|
wp-includes/post.php:
wp_check_for_changed_slugs()
|
Check for changed slugs for published post objects and save the old slug.
|
wp-includes/post.php:
wp_delete_attachment()
|
Trash or delete an attachment.
|
wp-includes/post.php:
wp_get_attachment_metadata()
|
Retrieves attachment metadata for attachment ID.
|
wp-includes/post.php:
wp_get_attachment_url()
|
Retrieve the URL for an attachment.
|
wp-includes/post.php:
wp_untrash_post_comments()
|
Restore comments for a post from the Trash.
|
wp-includes/post.php:
wp_insert_post()
|
Insert or update a post.
|
wp-includes/post.php:
wp_untrash_post()
|
Restores a post from the Trash.
|
wp-includes/post.php:
get_post_custom()
|
Retrieve post meta fields, based on post ID.
|
wp-includes/post.php:
get_post_status()
|
Retrieve the post status based on the post ID.
|
wp-includes/post.php:
get_attached_file()
|
Retrieve attached file path based on attachment ID.
|
wp-includes/author-template.php:
get_the_modified_author()
|
Retrieve the author who last edited the current post.
|
wp-includes/nav-menu.php:
wp_get_associated_nav_menu_items()
|
Get the menu items associated with a particular object.
|
wp-includes/nav-menu.php:
wp_setup_nav_menu_item()
|
Decorates a menu item object with the shared navigation menu item properties.
|
wp-includes/nav-menu.php:
wp_update_nav_menu_item()
|
Save the properties of a menu item or create a new one.
|
wp-includes/nav-menu.php:
wp_get_nav_menu_items()
|
Retrieves all menu items of a navigation menu.
|
wp-includes/class-wp-xmlrpc-server.php:
wp_xmlrpc_server::add_enclosure_if_new()
|
Adds an enclosure to a post if it’s new.
|
wp-includes/class-wp-xmlrpc-server.php:
wp_xmlrpc_server::_prepare_post()
|
Prepares post data for return in an XML-RPC object.
|
Return values when no meta field is found
If a meta field with the given $key isn’t found for the given $post_id, the return value varies:
If $single is true, an empty string is returned.
If $single is false, an empty array is returned.
Since both evaluate as false, you can use get_post_meta directly in conditionals, like this:
What if I want to store an empty string?
If for some reason your with to store an empty string or array into your meta field, get_post_meta will not be reliable when checking if the given meta field exists.
In this case, you can use get_post_custom_keys to do so:
Feedback
“If $single is true, an empty string is returned. If $single is false, an empty array is returned.” This is not true anymore. For Wordpress 5.2.2: If $single is true: if the meta value is scalar, null is returned; otherwise, an empty array is returned. If $single is false: if the meta value is scalar, an array containing one null element is returned; otherwise, an array containing one empty array is returned. Therefore, one can’t check if the key exists or not, in the case the meta value is an array, because it will return an empty array, whether the value is set or not. — By Alfredo Barbosa —
The best thing about this function is that you no longer need to use it :)
Since r21559 (v3.5), you can just call
$post->foo
to fetch the equivalent ofget_post_meta( $post->ID, 'foo', true )
.You can even extend that to introduce dynamically-generated fields, so you can call
echo esc_html( $post->bar )
instead of$bar = some_custom_logic( get_post_meta( $post->ID, 'bar', true ) ); echo esc_html( $bar )
.This makes code a lot cleaner and more readable.
Expand full source codeCollapse full source code
Feedback
If there are multiple values for the key “bar”,
$post->bar
will only return the first value.get_post_meta( get_the_ID(), 'bar')
will return all the values for the key “bar”. Multiple values can be added to a key using theadd_post_meta
function. Values can be removed withdelete_post_meta
. — By John Dorner —Show the first value of the specified key inside a loop
Default Usage
Get the meta for all keys for the current post:
Get all meta for a single key for the current post:
Get the first value of a meta key for the current post:
Retrieve a Custom Field Thumbnail Url
While you are in the WordPress Loop, you can use this code to retrieve a custom field. In this example, the thumbnail image url is in a custom field named “thumb”.
If you want to hide postmeta keys from the customfields prefix the key name with an underscore.
When you don’t specify a $key (”) and set $single to true in get_post_meta, it will return all keys still with an array of values.
When we calling for all post meta, it will returned array value:
sample output:
We can make it into string, array_column will resulting default array value into string, for sure we need array combine to re-form array key:
now output will be like here:
Post meta keys are case-sensitive
Display single meta value using meta key
If the value of the
$key
parameter is falsyget_post_meta
will return the entire post meta array, even if$single
is set totrue
. for example:Function The Retrieve a Number views in post
Expand full source codeCollapse full source code
False if post ID isn’t absint or is 0
Passing
$post_id == 0
(or anything not a absint) will return false no matter$single
.Feedback
Just for the record, WordPress returns either empty string (”) or an empty array (is_countable and count === 0) when you attempt to retrieve a meta value using a post ID or meta key that doesn’t exist. — By Brian Layman —
When I had tons of meta keys to work with to display some custom content for custom post types, instead of making several dozen calls to the get_post_meta function to grab the keys I wanted, I wrote this function instead. Basically it gets all of the meta keys and filters out all of the arrays with single values while maintaining any arrays that actually do have multiple values and returns an associative array of the results. If you have lots of single values to get, it saves you from having to iterate over every result to get your $k=>$v pairs so you can just access them by $mk[‘my_custom_meta_key’].
function array_push_assoc($array, $key, $value){
$array[$key] = $value;
return $array;
}
function filter_gpm($array){
$mk = array();
foreach($array as $k => $v){
if(is_array($v) && count($v) == 1){
$mk = array_push_assoc($mk, $k, $v[0]);
} else {
$mk = array_push_assoc($mk, $k, $v);
}
}
return $mk;
}
Call it like so
$mk = filter_gpm( get_post_meta( get_the_ID() ) );