How to update user profile custom fields

I use update_user_meta to update the fields. You can add this in functions.php of your child theme. function save_extra_user_profile_fields( $user_id ) { if ( !current_user_can( ‘edit_user’, $user_id ) ) { return false; } update_user_meta( $user_id, ‘telephone’, $_POST[‘telephone’] ); } add_action( ‘personal_options_update’, ‘save_extra_user_profile_fields’ ); add_action( ‘edit_user_profile_update’, ‘save_extra_user_profile_fields’ );

MetaBox not saving after empty

Here’s an updated version of save_TFP_meta(), which has modified saving logic. It fixes the issue where the meta data was not being saved after being emptied. function save_TFP_meta( $post_id, $post ) { if ( ! wp_verify_nonce( $_POST[‘TFP_meta_box_nonce’], plugin_basename( __FILE__ ) ) ) return $post_id; if ( ! current_user_can( ‘edit_post’, $post_id ) ) return $post_id; $TFP_meta_value … Read more

Set featured image from custom field URL

Hook ‘acf/save_post’ after ACF saves the $_POST[‘acf’] data. Then check to see if the post has_post_thumbnail and set_post_thumbnail if it doesn’t. function save_acf_image_to_post_thumbnail( $post_id ) { $image = get_field( ‘fl_image’ ); if ( ! empty ( $image ) ) { if ( ! has_post_thumbnail( $post_id ) ) { $image_id = isset( $image[ ‘id’ ] ) … Read more

TinyMCE custom button retrieve value from custom field

Rather than finding the custom field value when the user hits the button, change the [custom field value] to a shortcode name (perhaps “[mkay_subscription_button_value]”?) and then create a shortcode that can replace the value of that key with the post’s custom meta. Something like this: function 246286_display_custom_field( $atts ) { $data = get_post_meta( get_the_ID(), ‘mkay_custom_field’, … Read more