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

Loop through custom taxanomy in post and display custom fields from posts

You are going to need set up a new WP_Query in your content-*.php with the correct parameters in order to send it into a loop. <?php $args = array( ‘tax_query’ => array( array( ‘taxonomy’ => ‘recipes’,. ‘field’ => ‘slug’, ‘terms’ => ‘dessert’ ))); $your_posts = new WP_Query( $args ); ?> You can add any other … 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