File: /home/kochikidswysewor/www/wp-content/themes/children-charity-child/child-submission-new.php
<?php
include '../../../wp-load.php';
if($_REQUEST['action']===""){
echo "<script>alert('Invalid data!');window.location.href='".get_site_url()."'</script>";
}
if ( $_REQUEST['action']=="add-child" ){
$name=$_POST['name'];
$age=$_POST['age'];
$qualification=$_POST['qualification'];
$agency_name=$_POST['agency_name'];
$caseforchild = $_POST['caseforchild'];
$file_upload=$_FILES['profile_pic'];
$url = '';
if($_POST['name'] && $_POST['name']){
$post_id = wp_insert_post( array(
'post_type' => 'ourchild',
'post_title' => $_POST['name'],
'post_status' => 'publish',
) );
// my_acf_pre_save_post($post_id);
if( ! ( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) ) {
update_field( 'field_654a0d787b887', $age, $post_id );
update_field( 'field_654a0d837b888', $qualification, $post_id );
update_field( 'field_654a0de57b88a',0, $post_id );
update_field( 'field_654a0dee7b88b', 0, $post_id );
update_field( 'field_654a16c2d3108', $agency_name, $post_id );
update_field( 'field_654b21a266813', $caseforchild, $post_id);
// update_field( 'field_63ca95016c7b4', $branch_name, $post_id );
// update_field( 'field_63ca950d6c7b5', $ifsc_code, $post_id );
}
$url = '';
if (isset($file_upload))
{
$uploadedfile = $file_upload['name'];
$upload_name = $file_upload['name'];
$uploads = wp_upload_dir();
if (!function_exists('wp_handle_upload'))
{
require_once( ABSPATH . 'wp-admin/includes/file.php' );
}
// require_once ('../../../wp-admin/includes/image.php');
$upload_overrides = array(
'test_form' => false
);
$movefile = wp_handle_upload($file_upload, $upload_overrides);
if ($movefile && !isset($movefile['error']))
{
$file = $movefile['file'];
$url = $movefile['url'];
$type = $movefile['type'];
// media_handle_upload( $file_handler, 0 );
$attachment = array(
'post_mime_type' => $type,
'post_title' => $upload_name,
'post_parent' => $post_id
//'post_parent' => 0 //IF DONT WANT TO ATTACH POST ID
);
$attach_id = wp_insert_attachment($attachment, $file, $post_id);
// update_field( 'field_640eb2a117ae7', $attach_id, $post_id );
set_post_thumbnail( $post_id, $attach_id );
}
}
echo "Children Added Successfully";
}
}
?>