Display Repeatable Meta Box Content

Here’s a tested and working version of the template code, which displays the repeatable $emergency_contact_meta correctly: $member_contact_meta = get_post_meta( get_the_ID(), ‘tcp’, true ); echo ‘<strong>Phone: </strong>’ . $member_contact_meta . ‘<br />’; $emergency_contact_meta = get_post_meta( get_the_ID(), ‘repeatable_fields’, true); if ( $emergency_contact_meta ) { echo ‘<strong>Emergency Contacts:</strong><br />’; foreach ( $emergency_contact_meta as $emergency_contact_metas ) { echo ‘<strong>’ … Read more

Why does this update_post_meta function not delete the custom field itself?

You’re looking for delete_post_meta($post_id, $meta_key, $meta_value); Parameters $post_id (integer) (required) The ID of the post from which you will delete a field. Default: None $meta_key (string) (required) The key of the field you will delete. Default: None $meta_value (mixed) (optional) The value of the field you will delete. This is used to differentiate between several … Read more

meta box on new admin page

You are trying to create a new admin page with add_pages_page(). Meta boxes are only for existing post types, not for admin pages. You need to create your fields like on a normal admin page. You should read the official codex about this first: Creating Options Pages For a simple start take a look at … Read more

Set checkbox as checked by default in a metabox

You are saving unchecked checkbox values as empty strings: public function save_metabox( $post_id, $post ) { // Sanitize user input. $tp_primo_new_show_below_title = isset($_POST[‘tp_primo_show_below_title’]) ? ‘checked’ : ”; … } So when you fetch the saved unchecked value and then check for if(empty(…)), it returns true and sets ‘checked’ as the default value because empty(…): Returns … Read more

How to verify nonces in bulk?

You don’t need a nonce for every field, a single nonce should suffice This is because a nonce isn’t tied to a field, it’s tied to a request, and verifies that you did indeed intend to press update, or click a link, submit a form, etc As an example, back in the days of MySpace, … Read more

Wpautop in wp_editor not working

Normally, the wpautop filter is only applied to the_content and the_excerpt. In this case you want to apply it to metadata. So you’ll have to add the filter. If you look at get_post_meta, you’ll see that it is just a wrapper for get_metadata. So it doesn’t matter which one you use if you retrieve the … Read more