custom field (image) not saved

This topic contains 9 reply and 2 voices, and was last updated by lwrkrol 10 years, 7 months ago
Viewing 9 Posts - 1 through 9 (of 9 total)
Author Posts
September 5, 2013 at 10:22 pm 7837
lwrkrol I have a custom post type with an imagefield. I use the correct fieldname in the form, but it's not saving to the meta field of this CPT (which is saved in an array) I use this code in 'specialImage' => isset( $_POST['specialImage'] ) ? $_POST['specialImage'] : '', in the wpuf-functions.php Other custom fields are saved ok, should I use other code for an image ?
September 6, 2013 at 1:18 am 7841
lwrkrol lwrkrol

I changed the field type to text and then it’s saved correctly so it must be related to the image field.

September 8, 2013 at 11:58 am 7912
lwrkrol lwrkrol

But that is not what I want.

I want to select a file in my form and the path to the uploaded file should be stored in the meta field. So how to do this ?

September 8, 2013 at 12:21 pm 7916
Tareq Hasan Tareq Hasan

Please take a look here.

September 8, 2013 at 1:14 pm 7918
lwrkrol lwrkrol

Hi, I think I can get that working but the thing is that the other fields are stored using an array. I thought I could solve it like this, but it creates another metafield instead of adding it to the array.

$ait_dir_item = array (
‘address’ => isset( $_POST[‘address’] ) ? $_POST[‘address’] : ”,
‘zipcode’ => isset( $_POST[‘zipcode’] ) ? $_POST[‘zipcode’] : ”,
‘city’ => isset( $_POST[‘city’] ) ? $_POST[‘city’] : ”,
‘gpsLatitude’ => $def_lat,
‘gpsLongitude’ => $def_long,
‘streetViewLatitude’ => ”,
‘streetViewLongitude’ => ”,
‘streetViewHeading’ => ‘0’,
‘streetViewPitch’ => ‘0’,
‘streetViewZoom’ => ‘0’,
‘telephone’ => isset( $_POST[‘telephone’] ) ? $_POST[‘telephone’] : ”,
’email’ => isset( $_POST[’email’] ) ? $_POST[’email’] : ”,
‘web’ => isset( $_POST[‘web’] ) ? $_POST[‘web’] : ”,
‘facebooklink’ => isset( $_POST[‘facebooklink’] ) ? $_POST[‘facebooklink’] : ”,
‘twitterlink’ => isset( $_POST[‘twitterlink’] ) ? $_POST[‘twitterlink’] : ”,
‘hyveslink’ => isset( $_POST[‘hyveslink’] ) ? $_POST[‘hyveslink’] : ”,
‘youtubelink’ => isset( $_POST[‘youtubelink’] ) ? $_POST[‘youtubelink’] : ”,
‘pinterestlink’ => isset( $_POST[‘pinterestlink’] ) ? $_POST[‘pinterestlink’] : ”,
‘PayiDeal’ => isset( $_POST[‘PayiDeal’] ) ? $_POST[‘PayiDeal’] : ”,
‘PayPayPal’ => isset( $_POST[‘PayPayPal’] ) ? $_POST[‘PayPayPal’] : ”,
‘PayCreditCard’ => isset( $_POST[‘PayCreditCard’] ) ? $_POST[‘PayCreditCard’] : ”,
‘PayOverBoeking’ => isset( $_POST[‘PayOverBoeking’] ) ? $_POST[‘PayOverBoeking’] : ”,
‘thuiswinkel’ => isset( $_POST[‘thuiswinkel’] ) ? $_POST[‘thuiswinkel’] : ”,
‘mkbok’ => isset( $_POST[‘mkbok’] ) ? $_POST[‘mkbok’] : ”,
‘webshopkeurmerk’ => isset( $_POST[‘webshopkeurmerk’] ) ? $_POST[‘webshopkeurmerk’] : ”,
‘qshops’ => isset( $_POST[‘qshops’] ) ? $_POST[‘qshops’] : ”,
‘hoursMonday’ => isset( $_POST[‘hoursMonday’] ) ? $_POST[‘hoursMonday’] : ”,
‘hoursTuesday’ => isset( $_POST[‘hoursTuesday’] ) ? $_POST[‘hoursTuesday’] : ”,
‘hoursWednesday’ => isset( $_POST[‘hoursWednesday’] ) ? $_POST[‘hoursWednesday’] : ”,
‘hoursThursday’ => isset( $_POST[‘hoursThursday’] ) ? $_POST[‘hoursThursday’] : ”,
‘hoursFriday’ => isset( $_POST[‘hoursFriday’] ) ? $_POST[‘hoursFriday’] : ”,
‘hoursSaturday’ => isset( $_POST[‘hoursSaturday’] ) ? $_POST[‘hoursSaturday’] : ”,
‘hoursSunday’ => isset( $_POST[‘hoursSunday’] ) ? $_POST[‘hoursSunday’] : ”,
‘alternativeContent’ => isset( $_POST[‘alternativeContent’] ) ? $_POST[‘alternativeContent’] : ”,
‘specialTitle’ => isset( $_POST[‘specialTitle’] ) ? $_POST[‘specialTitle’] : ”,
‘specialContent’ => isset( $_POST[‘specialContent’] ) ? $_POST[‘specialContent’] : ”,
‘specialPrice’ => isset( $_POST[‘specialPrice’] ) ? $_POST[‘specialPrice’] : ”,
‘specialImage’ => isset( $_POST[‘specialImage’] ) ? $_POST[‘specialImage’] : ”,
);
update_post_meta( $post_id, ‘_ait-dir-item’, $ait_dir_item );
}

add_action( ‘wpuf_add_post_after_insert’, ‘wpufe_ait_integration’ );
add_action( ‘wpuf_edit_post_after_update’, ‘wpufe_ait_integration’ );

// save specialImage
function wpufe_copy_att_url( $post_id ) {
$field_name = ‘specialImageTmp’;
$attach_id = get_post_meta( $post_id, $field_name, true );

if ( $attach_id ) {
$meta_value = wp_get_attachment_url( $attach_id );
update_post_meta( $post_id, ‘specialImage’, $meta_value );
}
}

add_action( ‘wpuf_add_post_after_insert’, ‘wpufe_copy_att_url’ );
add_action( ‘wpuf_edit_post_after_update’, ‘wpufe_copy_att_url’ );

September 8, 2013 at 1:22 pm 7919
Tareq Hasan Tareq Hasan

FYI, the files could be accessed like this: $_POST['wpuf_files']['specialImage'], not just $_POST['specialImage']

September 8, 2013 at 2:18 pm 7922
lwrkrol lwrkrol

I’m not sure how to use that, when I change
‘specialImage’ => isset( $_POST[‘specialImage’] ) ? $_POST[‘specialImage’] : ”,

to

‘specialImage’ => isset( $_POST[‘wpuf_files’][‘specialImage’] ) ? $_POST[‘wpuf_files’][‘specialImage’] : ”,

I get the word: Array in that field.

September 8, 2013 at 3:23 pm 7926
Tareq Hasan Tareq Hasan

I think this is what you are looking for:
[php]
‘specialImage’ => isset( $_POST[‘wpuf_files’][‘specialImage’] ) ? wp_get_attachment_url( $_POST[‘wpuf_files’][‘specialImage’][0] ) : ”,
[/php]

September 8, 2013 at 3:29 pm 7928
lwrkrol lwrkrol

That worked, thank you very much Tareq!

September 9, 2013 at 12:42 pm 7945
lwrkrol lwrkrol

Weel it works when there is only 1 statement that does this. I wanted to add some more but then it’s not working anymore:
‘specialImage’ => isset( $_POST[‘wpuf_files’][‘specialImage’] ) ? wp_get_attachment_url( $_POST[‘wpuf_files’][‘specialImage’][0] ) : ”,
‘gallery1’ => isset( $_POST[‘wpuf_files’][‘gallery1’] ) ? wp_get_attachment_url( $_POST[‘wpuf_files’][‘gallery1’][0] ) : ”,
‘gallery2’ => isset( $_POST[‘wpuf_files’][‘gallery2’] ) ? wp_get_attachment_url( $_POST[‘wpuf_files’][‘gallery2’][0] ) : ”,

What am I doing wrong here ? The fields gallery1 and gallery2 stay empty

Viewing 9 Posts - 1 through 9 (of 9 total)