On this page
post_custom_meta_box( WP_Post $post )
Displays custom fields form fields.
Parameters
$postWP_Post Required-
Current post object.
Source
File: wp-admin/includes/meta-boxes.php. View all references
function post_custom_meta_box( $post ) {
?>
<div id="postcustomstuff">
<div id="ajax-response"></div>
<?php
$metadata = has_meta( $post->ID );
foreach ( $metadata as $key => $value ) {
if ( is_protected_meta( $metadata[ $key ]['meta_key'], 'post' ) || ! current_user_can( 'edit_post_meta', $post->ID, $metadata[ $key ]['meta_key'] ) ) {
unset( $metadata[ $key ] );
}
}
list_meta( $metadata );
meta_form( $post );
?>
</div>
<p>
<?php
printf(
/* translators: %s: Documentation URL. */
__( 'Custom fields can be used to add extra metadata to a post that you can <a href="%s">use in your theme</a>.' ),
__( 'https://wordpress.org/support/article/custom-fields/' )
);
?>
</p>
<?php
}
Related
Uses
| Uses | Description |
|---|---|
| list_meta() wp-admin/includes/template.php | Outputs a post’s public meta data in the Custom Fields meta box. |
| meta_form() wp-admin/includes/template.php | Prints the form in the Custom Fields meta box. |
| has_meta() wp-admin/includes/post.php | Returns meta data for the given post ID. |
| is_protected_meta() wp-includes/meta.php | Determines whether a meta key is considered protected. |
| current_user_can() wp-includes/capabilities.php | Returns whether the current user has the specified capability. |
| __() wp-includes/l10n.php | Retrieves the translation of $text. |
Changelog
| Version | Description |
|---|---|
| 2.6.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/post_custom_meta_box