Startseite › Toolset Professional Support › [Gelöst] Adding files manually to children post type
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
Verwandte Dokumentation:
Dieses Thema enthält 6 Antworten, hat 2 Stimmen.
Zuletzt aktualisiert von mohammadD vor 6 Jahren, 8 Monaten.
Assistiert von: Christian Cox.
I have children post type ,it has a file field. i have created a cred form and i have input like below :
<input type="file" name="msds[]" class="form-control msdsinput">
it should be an array of the files. i have also used cred api to get these files at cred_after_save , the code is like this :
$files = $_FILES['msds']; foreach($cmd as $key=>$f ) { $my_post = array( 'post_title' => $f, 'post_content' => 'cnt ubuntu', 'post-type' => 'post', 'post_status' => 'publish', 'comment_status' => 'closed', 'ping_status' => 'closed' ); // Insert the post into the database and get the resulting id back... $child_post_id = wp_insert_post( $my_post, $wp_error=true ); set_post_type( $child_post_id, 'inq-cmd' ); if(isset($files)) { $upload= wp_upload_bits($files["name"][$key], null, file_get_contents($files["tmp_name"][$key])); $url=$upload['url']; update_post_meta($child_post_id,'wpcf-msds',$url); } } update_post_meta($child_post_id, '_wpcf_belongs_' . $form_data['post_type'] . '_id', $post_id); }
it works when i just send a single file ( it's a bit slow though) . but it doesn't work when i use multiple files.
the form is in :
versteckter Link
i wanted to know is there a better way to handle uploading files with cred ? how should i update file field that i have created with types.
Wish to hear from you soon
Mohammad Darban Baran
Hi, can you provide the full hook code? Some critical information here is missing. The API name "cred_after_save" doesn't exist, and I need to know what $cmd represents here,:
foreach($cmd as $key=>$f )
In the new post arguments, this should be "post_type", not "post-type". You can set inq-cmd as the post type right here:
$my_post = array( 'post_title' => $f, 'post_content' => 'cnt ubuntu', 'post_type' => 'inq-cmd', 'post_status' => 'publish', 'comment_status' => 'closed', 'ping_status' => 'closed' );
Then you can delete this line, since it's not needed:
set_post_type( $child_post_id, 'inq-cmd' );
Thanks for the post type part , i will use that , if you want to know the whole API part it's like below :
add_action('cred_save_data', 'update_step',10,2); function update_step($post_id, $form_data) { // if a specific form if ($form_data['id']==13865) { if (isset($_POST['container']) && !isset($_POST['isLCL'])) { $fields = $_POST['container']; $quantity= $_POST['quantity']; $gross=$_POST['gross']; foreach($fields as $key=>$f ) { $my_post = array( 'post_title' => 'cnt'+$key, 'post_content' => 'cnt ubuntu', 'post-type' => 'post', 'post_status' => 'publish', 'comment_status' => 'closed', 'ping_status' => 'closed' ); // Insert the post into the database and get the resulting id back... $child_post_id = wp_insert_post( $my_post, $wp_error=true ); set_post_type( $child_post_id, 'inq-cnt' ); update_post_meta($child_post_id, 'wpcf-inq-cnt-container-size', $f); update_post_meta($child_post_id, 'wpcf-inq-cnt-quantity', $quantity[$key]); update_post_meta($child_post_id, 'wpcf-inq-cnt-gross-weight', $gross[$key]); update_post_meta($child_post_id, '_wpcf_belongs_' . $form_data['post_type'] . '_id', $post_id); } } $cmd = $_POST['cmdname']; $hs= $_POST['cmdhs']; $dng=$_POST['inq-dng']; $files = $_FILES['msds']; foreach($cmd as $key=>$f ) { $my_post = array( 'post_title' => $f, 'post_content' => 'cnt ubuntu', 'post-type' => 'post', 'post_status' => 'publish', 'comment_status' => 'closed', 'ping_status' => 'closed' ); // Insert the post into the database and get the resulting id back... $child_post_id = wp_insert_post( $my_post, $wp_error=true ); set_post_type( $child_post_id, 'inq-cmd' ); update_post_meta($child_post_id, 'wpcf-commodity-name', $f); update_post_meta($child_post_id, 'wpcf-commodity-hs-code', $hs[$key]); if($dng[$key]==1||$dng[$key]=='1') { update_post_meta($child_post_id, 'wpcf-inquiry-dangerous', $dng[$key]); if(isset($files)) { $upload= wp_upload_bits($files["name"][$key], null, file_get_contents($files["tmp_name"][$key])); /*$attachment_id = media_handle_upload( $files[$key], 0);*/ $url=$upload['url']; update_post_meta($child_post_id,'wpcf-msds',$url); } } update_post_meta($child_post_id, '_wpcf_belongs_' . $form_data['post_type'] . '_id', $post_id); } // add it to saved post meta add_post_meta($post_id,'wpcf-total-price',0); } }
and if you want to have the form it's like below :
[toolset_access role="Administrator,Sales,Customer" raw="true"] <div class="row"> <div class="col-md-12 hidden-xs "> <div id="map"> </div> </div> </div> [credform class='cred-form cred-keep-original inq-form'] [cred_field field='form_messages' value='' class='alert alert-warning'] <fieldset id="pold"> <legend> Basic info </legend> <div class="form-group" hidden> <label>[wpml-string context='cred-form-Inquiry-13865' name='Inquiry Name']Inquiry Name[/wpml-string]</label> [cred_field field='post_title' post='fdp_inquiry' value='' urlparam='' class='form-control' output='bootstrap'] </div> <div class="col-xs-12 col-md-12 row"> <div class="form-group col-xs-12 col-md-3"> <label>[wpml-string context='cred-form-Inquiry-13865' name='PoL']PoL[/wpml-string]</label> [cred_field field='inquiry-pol' post='fdp_inquiry' value='' urlparam='pol' select_text='--- not set ---' class='form-control' output='bootstrap'] </div> <div class="form-group col-xs-12 col-md-3"> <label>[wpml-string context='cred-form-Inquiry-13865' name='PoD']PoD[/wpml-string]</label> [cred_field field='inquiry-pod' post='fdp_inquiry' value='' urlparam='pod' select_text='--- not set ---' class='form-control' output='bootstrap'] </div> <div class="form-group col-xs-12 col-md-2"> <label>[wpml-string context='cred-form-Inquiry-13865' name='Type of Shipping']Type of Shipping[/wpml-string]</label> [cred_field field='type-of-cargo' post='fdp_inquiry' value='' urlparam='' select_text='--- not set ---' class='form-control' output='bootstrap'] </div> <div class="form-group col-xs-12 col-md-2"> <label>[wpml-string context='cred-form-Inquiry-13865' name='Type of packaging']Type of packaging[/wpml-string]</label> [cred_field field='inq-type-of-packaging' post='fdp_inquiry' value='' urlparam='' select_text='--- not set ---' class='form-control' output='bootstrap'] </div> <div class="form-group col-xs-12 col-md-2"> <label>[wpml-string context='cred-form-Inquiry-13865' name='LCL']Need LCL?[/wpml-string]</label> <div> <label class="cbx-container">[wpml-string context='cred-form-Inquiry-13865' name='LCL']Yes[/wpml-string]<input type="checkbox" value="1" name="isLCL" id="isLCL"> <span class="checkmark" style="top:2px!important"></span> </label> </div> </div> </div> </fieldset> <fieldset id="lclinfo" style="display:none;"> <legend> LCL info </legend> <div class="col-xs-12 col-md-10"> <div class="form-inline "> <div class="form-group"> <label class="sr-only" for="length">Length</label> <div class="input-group"> <input type="number" class="form-control" id="length" placeholder="Length" min="0"> <div class="input-group-addon">cm</div> </div> <label class="sr-only" for="width">Width</label> <div class="input-group"> <input type="number" class="form-control" id="width" placeholder="Width" min="0"> <div class="input-group-addon">cm</div> </div> <label class="sr-only" for="height">Height</label> <div class="input-group"> <input type="number" class="form-control" id="height" placeholder="Height" min="0"> <div class="input-group-addon">cm</div> </div> <label class="sr-only" for="weight">Weight</label> <div class="input-group"> <input type="number" class="form-control" id="weight" placeholder="Weight" min="0"> <div class="input-group-addon">kg</div> </div> </div> </div> </div> <div class="col-xs-12 col-md-2" id="chwid" style="display:none"> Chargeable wieght: <span id="chwi"></span> </div> </fieldset> <fieldset id="cntinfo"> <legend> Container info </legend> <div class="row"> <div class="controls"> <div class="multiple"> <div class="entry col-xs-12"> <div class="form-group col-xs-12 col-md-3"> <select class="form-control select2-cmd" name="container[]" select_text="Choose Container Type"> <option value="0">Container type</option> <option value="20ft-gp">20ft GP</option> <option value="40ft-dc">40ft DC</option> <option value="20ft-hd">20ft HD</option> <option value="40ft-hq">40ft Highcube</option> <option value="20ft-ref">20ft Refrigerated</option> <option value="40ft-ref">40ft Refrigerated</option> <option value="20ft-ot">20ft Open Top</option> <option value="40ft-ot">40ft Open Top</option> <option value="20ft-fr">20ft Flat rack</option> <option value="40ft-fr">40ft Flat rack</option> </select> </div> <div class="form-group col-xs-12 col-md-2"> <input type="number" class="form-control" placeholder="Quantity" name="quantity[]" min="1"> </div> <div class="form-group col-xs-12 col-md-2"> <div class="input-group"> <input type="number" class="form-control" placeholder="Gross weight" name="gross[]" min="1"> <span class="input-group-addon" id="kgaddon">kg</span> </div> </div> <div class="form-group col-md-3"> <span > <button class="btn btn-success btn-add" type="button"> <span class="glyphicon glyphicon-plus"></span> Add another container </button> </span> </div> </div> </div> </div> </div> </fieldset> <fieldset id="commodityinfo"> <legend> Commodity info </legend> <div class="controls2"> <div class="multiple2"> <div class="entry col-xs-12 row"> <div class="form-group col-xs-12 col-md-3"> <label>[wpml-string context='cred-form-Inquiry-13865' name='Commodity name']Commodity name[/wpml-string]</label> <input type="text" name="cmdname[]" class="form-control" required> </div> <div class="form-group col-xs-12 col-md-3"> <label>[wpml-string context='cred-form-Inquiry-13865' name='Commodity HS code']Commodity HS code[/wpml-string]</label> <input type="text" name="cmdhs[]" placeholder="optional" class="form-control"> </div> <div class="form-group col-xs-12 col-md-1"> <label>[wpml-string context='cred-form-Inquiry-13865' name='inquiry-dangerous1']Dangerous?[/wpml-string]</label> <div> <label class="cbx-container" for="cb-1">[wpml-string context='cred-form-Inquiry-13865' name='inquiry-dangerous2']Yes[/wpml-string]<input type="checkbox" value="1" name="inq-dng[]" class="inq-dng" id="cb-1"> <span class="checkmark"></span> </label> </div> </div> <div class="form-group col-md-3 msds" id="msds-1" style="display:none;"> <label for="msds-1">[wpml-string context='cred-form-Inquiry-13865' name='MSDS']MSDS[/wpml-string]</label> <input type="file" name="msds[]" class="form-control msdsinput"> </div> <div class="form-group col-xs-12"> <span> <button class="btn btn-success btn-add2" type="button"> <span class="glyphicon glyphicon-plus"></span> Add another comodity </button> </span> </div> </div> </div> </div> </fieldset> <div class="row" hidden> <div class="form-group" hidden> <label>[wpml-string context='cred-form-Inquiry-13865' name='Chargeable weight']Chargeable weight[/wpml-string]</label> [cred_field field='chargeable-weight' post='fdp_inquiry' value='' urlparam='' class='form-control' output='bootstrap'] </div> [cred_field field='inquiry-dangerous' post='fdp_inquiry' value='' urlparam='' output='bootstrap'] <div class="form-group" hidden> <label>[wpml-string context='cred-form-Inquiry-13865' name='Rate']Rate[/wpml-string]</label> [cred_field field='rate' post='fdp_inquiry' value='0' urlparam='' class='form-control' output='bootstrap'] </div> <div class="form-group" hidden> <label>[wpml-string context='cred-form-Inquiry-13865' name='Step']Step[/wpml-string]</label> [cred_field field='step' post='fdp_inquiry' value='1' urlparam='' output='bootstrap'] </div> </div> <fieldset id="optional info"> <legend> Optional info </legend> <div class="col-xs-12 row"> <div class="form-group col-xs-12 col-md-3"> <label>[wpml-string context='cred-form-Inquiry-13865' name='Ideal rate']Ideal rate[/wpml-string]</label> <div class="input-group"> [cred_field field='ideal-rate' post='fdp_inquiry' value='' urlparam='' placeholder='Enter your ideal rate' class='form-control' output='bootstrap'] <span class="input-group-addon" id="dollaraddon">$</span> </div> </div> <div class="form-group col-xs-12 col-md-3"> <label>[wpml-string context='cred-form-Inquiry-13865' name='Cargo ready time']Cargo ready time[/wpml-string]</label> [cred_field field='cargo-ready-time' post='fdp_inquiry' value='' urlparam='' placeholder='Choose cargo ready time' class='form-control' output='bootstrap'] </div> </div> </fieldset> <script> $( document ).ready(function() { $("input[name='post_title']").val(Math.floor(Math.random() * Math.floor(15000000))); }); </script> [cred_field field='recaptcha' value='' urlparam='' class='form-control' output='bootstrap'] [cred_field field='form_submit' value='Submit' urlparam='' class='btn btn-primary btn-lg' output='bootstrap'] [/credform] [/toolset_access] [toolset_access role="Administrator,Sales,Customer" operator="deny"]You should Sign-in or Sign-Up to proceed. You can find the links in the menu above [/toolset_access]
the js part :
var uluru; var map; var pol_marker; var pod_marker; var i=1; function inqChange() { integer=this.id.split("-")[1]; msdsid="#msds-"+integer; if(this.checked) { $(msdsid).fadeIn(); $(msdsid+"> input").rules('add', { required: true }); } else { $(msdsid).fadeOut(); $(msdsid+"> input").rules('remove','required'); } } $(document).ready(function() { $( "form" ) .attr( "enctype", "multipart/form-data" ) .attr( "encoding", "multipart/form-data" ) ; $('.wpt-form-select').select2(); uluru = {lat: 0, lng: 0}; map = new google.maps.Map(document.getElementById('map'), { zoom: 2, minZoom:2, center: uluru }); pol_marker =new google.maps.Marker({ position: {lat: 0, lng: 0}, map: map, visible: false }); pod_marker =new google.maps.Marker({ position: {lat: 0, lng: 0}, map: map, visible: false }); if($('select[name="wpcf-inquiry-pol"]').val() !=="") { var geocoder = new google.maps.Geocoder(); geocoder.geocode( { 'address': $('select[name="wpcf-inquiry-pol"]').val()}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { var point = {lat: results[0].geometry.location.lat(), lng: results[0].geometry.location.lng()}; pol_marker.setPosition(point); pol_marker.setVisible(true); map.setZoom(2); map.panTo(point); } else { alert("Something got wrong " + status); } //} });} if($('select[name="wpcf-inquiry-pod"]').val() !=="") { var geocoder = new google.maps.Geocoder(); geocoder.geocode( { 'address': $('select[name="wpcf-inquiry-pod"]').val()}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { var point = {lat: results[0].geometry.location.lat(), lng: results[0].geometry.location.lng()}; pod_marker.setPosition(point); pod_marker.setVisible(true); map.setZoom(2); map.panTo(point); } else { alert("Something got wrong " + status); } //} });} }); $(function() { $(document).on('click', '.btn-add', function(e) { e.preventDefault(); var controlForm = $('.controls .multiple:first'), currentEntry = $(this).parents('.entry:first'), newEntry = $(currentEntry.clone()).appendTo(controlForm); newEntry.find('input').val(''); controlForm.find('.entry:not(:last) .btn-add') .removeClass('btn-add').addClass('btn-remove') .removeClass('btn-success').addClass('btn-danger') .html('<span class="glyphicon glyphicon-minus"></span>'); }).on('click', '.btn-remove', function(e) { $(this).parents('.entry:first').remove(); e.preventDefault(); return false; }); }); $(function() { $(document).on('click', '.btn-add2', function(e) { e.preventDefault(); var controlForm = $('.controls2 .multiple2:first'), currentEntry = $(this).parents('.entry:first'), newEntry = $(currentEntry.clone()); i=i+1; newEntry.find('input').val(''); newEntry.find('input[type="checkbox"]').val('1'); newEntry.find('input[type="checkbox"]').attr('id','cb-'+i); id="cb-"+i; newEntry.find('.cbx-container').attr('for','cb-'+i); newEntry.find('.inq-dng').removeAttr('checked'); newEntry.find('.msds').hide(); newEntry.find('.msds').attr('id','msds-'+i); newEntry.appendTo(controlForm); element=document.getElementById(id); element.onchange=inqChange; controlForm.find('.entry:not(:last) .btn-add2') .removeClass('btn-add2').addClass('btn-remove2') .removeClass('btn-success').addClass('btn-danger') .html('<span class="glyphicon glyphicon-minus"></span>'); }).on('click', '.btn-remove2', function(e) { $(this).parents('.entry:first').remove(); e.preventDefault(); return false; }); }); $('#isLCL').change(function() { if(this.checked) { $('#lclinfo').fadeToggle(); $('#cntinfo').hide(); } else { $('#lclinfo').hide(); $('#cntinfo').fadeToggle(); } }); $('#cb-1').change(function() { if(this.checked) { $('#msds-1').fadeIn(); $('#msds-1>input').rules('add', { required: true }); } else { $('#msds-1').fadeOut(); $('#msds-1>input').rules('remove','required'); } }); $('#length,#width,#height,#weight').change(function() { $('#chwi').empty(); var vlength=$('#length').val(); var vwidth=$('#width').val(); var height=$('#height').val(); var weight=$('#weight').val(); if((vlength/10)*(vwidth/10)*(height/10) >weight) {$('#chwid').fadeOut(); $('#chwi').text((vlength/10)*(vwidth/10)*(height/10)); $('#chwid').fadeIn(); $("input[name='wpcf-chargeable-weight']").val((vlength/10)*(vwidth/10)*(height/10)); } else {$('#chwid').fadeOut(); $('#chwi').text(weight); $('#chwid').fadeIn(); $("input[name='wpcf-chargeable-weight']").val(weight); } }); $('select[name="wpcf-inquiry-pol"]').on('change' ,function() { var geocoder = new google.maps.Geocoder(); if($('select[name="wpcf-inquiry-pol"]').val() !=="") { geocoder.geocode( { 'address': $('select[name="wpcf-inquiry-pol"]').val()}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { var point = {lat: results[0].geometry.location.lat(), lng: results[0].geometry.location.lng()}; pol_marker.setPosition(point); pol_marker.setVisible(true); map.setZoom(2); map.panTo(point); } else { alert("Something got wrong " + status); } //} });} }); $('select[name="wpcf-inquiry-pod"]').on('change' ,function() { var geocoder = new google.maps.Geocoder(); if($('select[name="wpcf-inquiry-pod"]').val() !=="") { geocoder.geocode( { 'address': $('select[name="wpcf-inquiry-pod"]').val()}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { var point = {lat: results[0].geometry.location.lat(), lng: results[0].geometry.location.lng()}; pod_marker.setPosition(point); pod_marker.setVisible(true); map.setZoom(2); map.panTo(point); } else { alert("Something got wrong " + status); } //} });} });
the css part :
.entry:not(:first-of-type) { margin-top: 10px; } .glyphicon { font-size: 12px; } .cbx-container input[type="checkbox"] { position: absolute; opacity: 0; cursor: pointer; } /* Create a custom checkbox */ .checkmark { position: absolute; top: 5px; left: 0; height: 25px; width: 25px; background-color: #eee; } /* On mouse-over, add a grey background color */ .cbx-container:hover input ~ .checkmark { background-color: #ccc; } /* When the checkbox is checked, add a blue background */ .cbx-container input:checked ~ .checkmark { background-color: #2196F3; } /* Create the checkmark/indicator (hidden when not checked) */ .checkmark:after { content: ""; position: absolute; display: none; } /* Show the checkmark when checked */ .cbx-container input:checked ~ .checkmark:after { display: block; } /* Style the checkmark/indicator */ .cbx-container .checkmark:after { left: 9px; top: 5px; width: 5px; height: 10px; border: solid white; border-width: 0 3px 3px 0; -webkit-transform: rotate(45deg); -ms-transform: rotate(45deg); transform: rotate(45deg); } .cbx-container { display: block; position: relative; padding-left: 35px; margin-bottom: 12px; cursor: pointer; font-size: 15px; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } input { color:black!important; height:34px!important; } #map { width:100%; min-height:400px; margin: 20px 0px 20px 0px; } #sc-chm{ top:5px!important; }
I am sure you may not need them all but i have given you all of them ,if it's a bit confusing feel free to ask and i am sorry for bad coding .
Thanks in advance
Please add some log statements to the hook here:
if(isset($files)) { error_log('----- files ----------'); error_log(print_r($files, true)); $upload= wp_upload_bits($files["name"][$key], null, file_get_contents($files["tmp_name"][$key])); $url=$upload['url']; update_post_meta($child_post_id,'wpcf-msds',$url); }
Then turn on server logs. If you're not familiar with your environment's server logs, I can show you how to enable them temporarily. Go in your wp-config.php file and look for define(‘WP_DEBUG’, false);. Change it to:
define('WP_DEBUG', true);
Then add these lines, just before it says 'stop editing here':
ini_set('log_errors',TRUE); ini_set('error_reporting', E_ALL); ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
Try to submit the form again - once with only one file, and once with multiple files. This should create an error_log.txt file in your site's root directory. Please send me its contents. Once that is done, you can revert the changes you made to wp-config.php.
[27-Mar-2018 19:26:46 UTC] ----- files ---------- [27-Mar-2018 19:26:46 UTC] Array ( [name] => Array ( [0] => نمرات تمارین.pdf ) [type] => Array ( [0] => application/pdf ) [tmp_name] => Array ( [0] => /tmp/phpBIZ2c6 ) [error] => Array ( [0] => 0 ) [size] => Array ( [0] => 207356 ) ) [27-Mar-2018 19:28:19 UTC] ----- files ---------- [27-Mar-2018 19:28:19 UTC] Array ( [name] => Array ( [0] => سازمان سنجش آموزش کشور.pdf [1] => tasvir.jpg [2] => ) [type] => Array ( [0] => application/pdf [1] => image/jpeg [2] => ) [tmp_name] => Array ( [0] => /tmp/phpLxDNhL [1] => /tmp/php7UUWEJ [2] => ) [error] => Array ( [0] => 0 [1] => 0 [2] => 4 ) [size] => Array ( [0] => 119082 [1] => 13543 [2] => 0 ) ) [27-Mar-2018 19:28:19 UTC] ----- files ---------- [27-Mar-2018 19:28:19 UTC] Array ( [name] => Array ( [0] => سازمان سنجش آموزش کشور.pdf [1] => tasvir.jpg [2] => ) [type] => Array ( [0] => application/pdf [1] => image/jpeg [2] => ) [tmp_name] => Array ( [0] => /tmp/phpLxDNhL [1] => /tmp/php7UUWEJ [2] => ) [error] => Array ( [0] => 0 [1] => 0 [2] => 4 ) [size] => Array ( [0] => 119082 [1] => 13543 [2] => 0 ) )
I think it works fine but check it any way , it had some issued with speed , should i delete temp files ? if yes how .
i wanted to know is there a better way to handle uploading files with cred ? how should i update file field that i have created with types.
Can you explain why is this file input field is necessary? Why not use a Types repeating "file" custom field?
it works when i just send a single file ( it's a bit slow though) . but it doesn't work when i use multiple files.
Check out the WordPress documentation for update_post_meta:
https://codex.wordpress.org/Function_Reference/update_post_meta
update_post_meta( $post_id, $meta_key, $meta_value, $prev_value );
The last parameter, $prev_value, is important when you're dealing with repeating fields. If multiple values exist for this field, and you do not include the 4th parameter when you call update_post_meta, all the values will be overwritten with the same new value. So in the Create New CRED form, you can call add_post_meta instead to be sure all the values are added correctly. Then when you submit the Edit CRED form, you have to be careful that you are updating only one value each time...or you can delete all the old values and add all the values again using add_post_meta.
So can you explain what does not work, exactly?
- Are any files uploaded to the uploads directory? Which ones?
- Are any server-side errors thrown?
- Are any postmeta values added to the child post? What value or values?
I needed that because i should have created a file for each child, but repeating field is suggesting multiple files for a same child. and i wanted to create childeren after the parent form were submitted.
Your help in understanding the file structure and input were outstanding , i will use your advice on repeating fields later in my projects.
With thanks and regards
Mohammad Darban Baran