post_custom_meta_box

函数
post_custom_meta_box ( $post )
参数
  • (WP_Post) $post Current post object.
    Required:
定义位置
相关方法
post_author_meta_boxpost_comment_meta_boxpost_submit_meta_boxpost_format_meta_boxpost_tags_meta_box
引入
2.6.0
弃用
-

post_custom_meta_box: 此函数用于在文章编辑界面显示自定义字段元框,允许用户从文章中添加或删除自定义字段。

显示自定义字段表单字段。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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
}
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 }
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
}

常见问题

FAQs
查看更多 >