Home Forums Plugin Support WP User Frontend Pro custom field (image) not saved

This topic is: resolved

Tagged: , , , ,

This topic contains 9 replies, has 2 voices, and was last updated by  lwrkrol 5 years, 10 months ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #7837

    lwrkrol
    Participant
    Post count: 9

    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 ?

    #7841

    lwrkrol
    Participant
    Post count: 9

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

    #7912

    lwrkrol
    Participant
    Post count: 9

    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 ?

    #7916

    Tareq Hasan
    Keymaster
    Post count: 2831
    #7918

    lwrkrol
    Participant
    Post count: 9

    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' );

    #7919

    Tareq Hasan
    Keymaster
    Post count: 2831

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

    #7922

    lwrkrol
    Participant
    Post count: 9

    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.

    #7926

    Tareq Hasan
    Keymaster
    Post count: 2831

    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]

    #7928

    lwrkrol
    Participant
    Post count: 9

    That worked, thank you very much Tareq!

    #7945

    lwrkrol
    Participant
    Post count: 9

    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 10 posts - 1 through 10 (of 10 total)

The topic ‘custom field (image) not saved’ is closed to new replies.