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: 此函式用於在文章編輯介面顯示自定義欄位元框,允許使用者從文章中新增或刪除自定義欄位。

顯示自定義欄位表單欄位。

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
檢視更多 >