Forked from juyal-ahmed/wp-featured-image-upload-for-front-end.php
Created
February 21, 2018 03:48
-
-
Save r17x/44d13b4eeb03b24d9c83fef7e442937f to your computer and use it in GitHub Desktop.
Upload featured image on custom post from WordPress front-end
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Just uploading photo or attachments | |
require_once(ABSPATH . "wp-admin" . '/includes/image.php'); | |
require_once(ABSPATH . "wp-admin" . '/includes/file.php'); | |
require_once(ABSPATH . "wp-admin" . '/includes/media.php'); | |
$file_handler = 'upload_attachment' //Form attachment Field name. | |
$attach_id = media_handle_upload( $file_handler, $post_id ); | |
//making it featured! | |
set_post_thumbnail($post_ID, $attach_id ); | |
or | |
update_post_meta($post_id,'_thumbnail_id',$attach_id); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment