1

I'm trying to use admin/upload.php to upload featured image from front end form.

All I have to do is put below code in the front end form

<div id="postimagediv" class="postbox ">
    <div class="handlediv" title="Click to toggle"><br></div>
    <h3 class="hndle ui-sortable-handle"><span>Featured Image</span></h3>
    <div class="inside">
        <p class="hide-if-no-js"><a title="Set featured image" href="http://localhost:8888/WordPress/wp-admin/media-upload.php?post_id=POST_ID&amp;type=image&amp;TB_iframe=1&amp;width=753&amp;height=491" id="set-post-thumbnail" class="thickbox">Set featured image</a></p>
    </div>
</div>

media-upload.php seems to be taking care of most of featured image functions (AJAX uploading and remove featured image through AJAX)

The problem is I can't get the post_id on front end from before actually submitting the entire form.

below is the only way I can get post_id after submitting the form

$post_id = wp_insert_post($new_post);

Is there a way to give temporary id to the post_id and update it when form is submitted?

or get post_id as soon as front end form is loaded? cause I notice when you write post in backend, you immediately get the post_id when you click Add New button.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.