• hello,

    I searched here long time, how can I update a picture and could not find any suitable solution. I have created a front-end form, with which I can edit the content of posts. I can without Problem update the content. But only the image field would not updated.

    <input type="file" id="headerimage" name="headerimage" />
    After Submitting the From:

    $post_information = array(
    		'ID' => $current_post,
    		'post_title' => esc_attr(strip_tags($_POST['postTitle'])),
    		'post_content' => $_POST['postContent'],
    		'post-type' => 'page',
    		'post_status' => 'publish'
    	);
    $post_update = wp_update_post($post_information);
    update_post_meta($current_post,'_url', $_POST['headerimage']);
    image_attachment($_POST['headerimage'], $current_post);

    the Function: image_attachment

    function image_attachment($file_handler,$post_id,$set_thu=false) {
    	// check to make sure its a successful upload
    	if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK) __return_false();
    
    	require_once(ABSPATH . "wp-admin" . '/includes/image.php');
    	require_once(ABSPATH . "wp-admin" . '/includes/file.php');
    	require_once(ABSPATH . "wp-admin" . '/includes/media.php');
    
    	$attach_id = media_handle_upload( $file_handler, $post_id );
    
             // If you want to set a featured image frmo your uploads.
    	if ($set_thu) set_post_thumbnail($post_id, $attach_id);
    	return $attach_id;
    }

    It works well. But the record of the image will not be updated.

    Maybe one of you can help me. For any help I would be grateful. Thanks in advance

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘update_post_meta – Update image URL’ is closed to new replies.