<a href="https://console.cloud.google.com/apis/credentials">Get Your Api Credentials Here</a> <a href="https://calendar.google.com/calendar">Get your Calender ID</a> <?php include_once("wp-load.php"); function get_calender_events() { $params = array(); /*Get current date*/ $current_date = date('Y-m-d H:i:s'); /*Convert it to google calendar's rfc_format */ $rfc_format = date("c", strtotime($current_date)); $params[] = 'orderBy=startTime'; $params[] ='maxResults=100'; $params[] = 'timeMin='.urlencode($rfc_format); $url_param = ''; foreach($params as $param) { $url_param.= '&'.$param; } $calender_id = "calender_id"; $client_key = "client_key"; $url = "https://www.googleapis.com/calendar/v3/calendars/".$calender_id."/events?key=".$client_key."&singleEvents=true".$url_param; $list_events = wp_remote_post($url, ...
//ceate a template file
<?php acf_form_head(); ?>
<?php
/*
Template Name: Front End Form
*/
?>
<?php get_header(); ?>
<form method="post" action="#" class="acf-form" id="post" enctype="multipart/form-data">
<?php
$args = array(
'post_id' => 'new',
'field_groups' => array(1), //it's the ID of your custom field Form
'form' => false
);
acf_form( $args );
?>
<!--http://codex.wordpress.org/Function_Reference/media_handle_upload-->
<div data-field_type="file" data-field_key="field_5343d9b2586f0file" data-field_name="email" class="field field_type-text field_key-field_5343d9b2586f0file" id="acf-file">
<p class="label"><label for="acf-field-file">Image</label></p>
<div class="acf-input-wrap">
<input type="file" id="my_image_upload" name="my_image_upload">
</div>
<p class="label"><label for="acf-field-file">PDF</label></p>
<div class="acf-input-wrap">
<input type="file" id="pdf" name="pdf">
</div>
</div>
<input id="submit_my_image_upload" name="submit_my_image_upload" type="submit" value="Submit" />
</form>
<?php get_footer(); ?>
***
add in function.php
<?php
add_filter('acf/pre_save_post' , 'my_pre_save_post' );
function my_pre_save_post( $post_id ) {
// save code here
$my_post = array(
'post_title' => "asdsa",
'post_content' => "content",
'post_type'=>'resources',
'post_status' => 'pending',
'filter' => false,
'post_author' => get_current_user_id(),
);
// Insert the post into the database.
$post_id = wp_insert_post( $my_post );
wp_set_object_terms( $post_id, $looking_for, 'looking_for' );
wp_set_object_terms( $post_id, $age_group, 'age_group' );
wp_set_object_terms( $post_id, $about, 'about' );
wp_set_object_terms( $post_id, "ssssssss,545,uuu", 'resources_tags' );
/*
image and pdf upload in acf
// Create a new post
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
require_once(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/media.php');
$attachment_id = media_handle_upload( 'my_image_upload', $post_id );
update_field('my_image_upload', $attachment_id, $post_id);
$attachment_id = media_handle_upload( 'pdf', $post_id );
update_field('pdf', $attachment_id, $post_id);
*/
if ( !function_exists('wp_handle_upload') ) {
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
require_once(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/media.php');
}
// Move file to media library
$movefile = wp_handle_upload( $_FILES['my_image_upload'], array('test_form' => false) );
// If move was successful, insert WordPress attachment
if ( $movefile && !isset($movefile['error']) ) {
$wp_upload_dir = wp_upload_dir();
$attachment = array(
'guid' => $wp_upload_dir['url'] . '/' . basename($movefile['file']),
'post_mime_type' => $movefile['type'],
'post_title' => preg_replace( '/\.[^.]+$/', "", basename($movefile['file']) ),
'post_content' => "",
'post_status' => 'inherit'
);
$attach_id = wp_insert_attachment($attachment, $movefile['file']);
// Assign the file as the featured image
set_post_thumbnail($post_id, $attach_id);
update_field('my_image_upload', $attach_id, $post_id);
$attachment_id = media_handle_upload( 'pdf', $post_id );
update_field('pdf', $attachment_id, $post_id);
}
return $post_id;
}
Comments
Post a Comment