Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1013873

    Hello,
    I added the code below to my Enfold theme last year (October 2017) to add the “Don’t display image on single post” check box to a specific post type (“person”). As of last week, it seems that the check box is no longer saving as “checked”. My goal is to have a feature image selected for each person post so that another page listing all “person” post types will display the image, but I’m using a different version of the image / layout in the post itself. Any insight into why this might have stopped working? I’m running WordPress 4.9.8.
    Thanks!
    Hannah

    
    add_filter( 'admin_post_thumbnail_html', 'mmx_cpt_featured_image_meta');
    function mmx_cpt_featured_image_meta( $content ) {
    	global $post, $post_type;
    	if( $post_type == "person" ) {
    		$text = __( "Don't display image on single post", 'avia_framework' );
    		$id = '_avia_hide_featured_image';
    		$value = esc_attr( get_post_meta( $post->ID, $id, true ) );
    		$selected = !empty($value) ? "checked='checked'" : "";
    		$label = '</div><div class="av-meta-extra-inside"><label for="' . $id . '" class="selectit"><input '.$selected.' name="' . $id . '" type="checkbox" id="' . $id . '" value="1" > ' . $text .'</label>';
    		return $content .= $label;
    	}
    	return $content;
    }
    
    		?>
    
    #1014075

    Hey wiredlab,

    Your code just adds the post meta but does not save it. You can use this code to save the field data:

    
    add_action( 'save_post', 'mmx_cpt_featured_image_meta_save');
    function mmx_cpt_featured_image_meta_save( $post_id )
    {
        if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
    
        if ( 'page' == $_POST['post_type'] ) 
        {
            if ( !current_user_can( 'edit_page', $post_id ) )
            return;
        }
        else
        {
            if ( !current_user_can( 'edit_post', $post_id ) )
            return;
        }
    
        $data = $_POST['_avia_hide_featured_image'];
        update_post_meta($post_id, '_avia_hide_featured_image', $data);
    }
    

    Best regards,
    Peter

    #1017594

    That helped. Thank you so much, Peter!

    #1017746

    Hi,

    Great, glad we could help :-)

    Please let us know if you should need any further help on the topic or if we can close it.

    Best regards,
    Rikard

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.