Forked from juyal-ahmed/wp-featured-image-upload-for-front-end.php
Created
January 23, 2017 00:12
-
-
Save beatwiz/537afdf39e8b50627db04947344f995a to your computer and use it in GitHub Desktop.
Upload featured image on custom post from WordPress front-end
This file contains 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