Viewing 4 posts - 1 through 4 (of 4 total)
-
AuthorPosts
-
September 24, 2018 at 10:16 pm #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!
Hannahadd_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; } ?>
September 25, 2018 at 9:41 am #1014075Hey 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,
PeterOctober 3, 2018 at 8:17 pm #1017594That helped. Thank you so much, Peter!
October 4, 2018 at 8:11 am #1017746 -
AuthorPosts
Viewing 4 posts - 1 through 4 (of 4 total)
- You must be logged in to reply to this topic.