post_custom_meta_box() WordPress Function

The post_custom_meta_box() function is a powerful tool that allows you to add custom fields to your posts and pages. Using this function, you can add text, images, and other data to your posts and pages, making them more engaging and informative. Additionally, you can use this function to create custom fields for your comments section, allowing you to gather more information from your readers.

post_custom_meta_box( WP_Post $post ) #

Displays custom fields form fields.


Parameters

$post

(WP_Post)(Required)Current post object.


Top ↑

Source

File: wp-admin/includes/meta-boxes.php

764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
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>.' ),
    );
    ?>
</p>
    <?php
}


Top ↑

Changelog

Changelog
VersionDescription
2.6.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by the Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.