Home / Admin / Post Meta Debugger
Duplicate Snippet

Embed Snippet on Your Site

Post Meta Debugger

Add a metabox that lists all the custom fields/meta values for a post/page for easy debugging.

100+
Code Preview
php
<?php
add_action( 'add_meta_boxes', function () {
	if ( ! current_user_can( 'manage_options' ) ) {
		// Don't display the metabox to users who can't manage options
		return;
	}
	add_meta_box( 'wpcode-view-post-meta', 'Post Meta', function () {
		$custom_fields = get_post_meta( get_the_ID() );
		?>
		<table style="width: 100%; text-align: left;">
			<thead>
			<tr>
				<th style="width: 28%">Meta Key</th>
				<th style="width: 70%">Value</th>
			</tr>
			</thead>
			<tbody>
			<?php foreach ( $custom_fields as $key => $values ) {
				?>
				<?php foreach ( $values as $value ) { ?>
					<tr>
						<td><?php echo esc_html( $key ); ?></td>
						<td><code><?php echo esc_html( $value ); ?></code></td>
					</tr>
				<?php } ?>
			<?php } ?>
			</tbody>
		</table>
		<?php
	}, get_post_type() );
} );

Comments

Add a Comment