Home › Forums › Quform WordPress › How to automatically create a post?
- This topic has 18 replies, 2 voices, and was last updated 11 years, 6 months ago by Ally.
- AuthorPosts
- April 27, 2013 at 9:43 am #4128haritosParticipant
Hello!
I want to create a post automatically after a submission of a form i created. So if there are 3 custom fields such as: Title, Content and Date , i want to automatically create a draft.
But if the date field didn’t filled must not been displayed in the post. Also how can i insert an image as featured image?
April 27, 2013 at 9:48 am #4129AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
April 27, 2013 at 9:56 am #4130haritosParticipantYes i read it!
But i don’t want to use it in custom posts type but in default post and then i want to not display the fields that aren’t filled in the submission!
How to do that?
April 27, 2013 at 10:01 am #4131haritosParticipantAlso how to intergate with Advanced Custom Fields? I want to insert the submitted fields in the QuForm into the Advanced Custom Fields i created in the post!
April 27, 2013 at 10:33 am #4132AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
April 27, 2013 at 1:31 pm #4133haritosParticipantI tried to find our conversation but i can’t! If you could sent it me i would appreciate it! Thank you!
April 28, 2013 at 8:41 am #4136haritosParticipantApril 29, 2013 at 8:20 am #4143AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
April 29, 2013 at 1:49 pm #4157haritosParticipantYes i saw it!
Thank you!
May 1, 2013 at 7:25 pm #4217haritosParticipantHey Ally,
Can you help me on how to insert an image tp the post uploaded via the form?
You gave me this code:
// Insert the post
$post_id = wp_insert_post($post);// Add attachments
$file = $form->getValue('iphorm_2_4');if (isset($file[0])) {
$file = $file[0];
$filename = $file['text'];
$path = $file['fullPath'];$wp_filetype = wp_check_filetype($filename, null);
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_title' => sanitize_file_name($filename),
'post_content' => '',
'post_status' => 'inherit'
);$attach_id = wp_insert_attachment($attachment, $path, $post_id);
require_once(ABSPATH . 'wp-admin/includes/image.php');
$attach_data = wp_generate_attachment_metadata( $attach_id, $path );
wp_update_attachment_metadata( $attach_id, $attach_data );set_post_thumbnail( $post_id, $attach_id );
And you told me to add this:
$value = array(
'url' => iphorm_get_wp_uploads_url() . '/' . $result['path'] . $filename,
'text' => $filename,
'fullPath' => $fullPath
);But it gives me an error!
Please help!
May 2, 2013 at 11:51 am #4233AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
May 3, 2013 at 8:20 am #4248haritosParticipantHi Ally,
You are totally right!
I have one more problem.. It may be yours or the ACF Plugin!
I have three fields in the ACF and i want to autofill them with the submitted form data. I can do this for all other fields but with these three i can’t!
The fields are a date picker, a text and a checkbox.
Can you help me?
May 5, 2013 at 4:16 pm #4270AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
May 6, 2013 at 11:11 am #4288haritosParticipantThanks for the notification but where do i have to put the checkbox array?
i use this code:
add_action('iphorm_post_process_1', 'mytheme_create_wp_post', 10, 1);
function mytheme_create_wp_post($form)
{
$title = $form->getValue('iphorm_1_1');
$content .= 'Δώρα διαγωνισμού: ' . $form->getValueHtml('iphorm_1_30') . '<br />';
$content .= 'Κατηγορία διαγωνισμού: ' . $form->getValueHtml('iphorm_1_39') . '<br />';
$content .= 'Διοργανωτής διαγωνισμού: ' . $form->getValueHtml('iphorm_1_36') . '<br />';
$content .= 'Απαιτείται λογαριασμός Facebook: ' . $form->getValueHtml('iphorm_1_45') . '<br />';
$content .= 'Περιορισμός περιοχής: ' . $form->getValueHtml('iphorm_1_15') . '<br />';
$content .= 'Ημερομηνία λήξης: ' . $form->getValueHtml('iphorm_1_8') . '<br />';
$content .= 'Ώρα λήξης: ' . $form->getValueHtml('iphorm_1_9') . '<br />';
$content .= 'Όροι διαγωνισμού: ' . $form->getValueHtml('iphorm_1_32') . '<br />';
$content .= 'Πληροφορίες διαγωνισμού: ' . $form->getValueHtml('iphorm_1_35') . '<br />';
$link .= 'Link διαγωνισμού: ' . $form->getValueHtml('iphorm_1_11') . '<br />';$post = array(
'post_title' => $title,
'post_content' => $content,
'post_status' => 'draft'
);$post_id = wp_insert_post($post);
add_post_meta($post_id, 'dwra_diagwnismou', $form->getValue('iphorm_1_30'));
add_post_meta($post_id, 'category', $form->getValue('iphorm_1_39'));
add_post_meta($post_id, 'diorganwths_diagwnismou', $form->getValue('iphorm_1_36'));
add_post_meta($post_id, 'apaitei_logariasmo_facebook', $form->getValue('iphorm_1_45'));
add_post_meta($post_id, 'periorismos_perioxhs', $form->getValue('iphorm_1_15'));
add_post_meta($post_id, 'hmeromhnia_lhkshs', $form->getValue('iphorm_1_8'));
add_post_meta($post_id, 'wra_lhkshs', $form->getValue('iphorm_1_9'));
add_post_meta($post_id, 'link_diagwnismou', $form->getValue('iphorm_1_11'));
add_post_meta($post_id, 'oroi_diagwnismou', $form->getValue('iphorm_1_32'));
add_post_meta($post_id, 'plhrofories_diagwnismou', $form->getValue('iphorm_1_35'));// Add attachments
$file = $form->getValue('iphorm_1_10');if (isset($file[0]))
{
$file = $file[0];
$filename = $file['text'];
$path = $file['fullPath'];$wp_filetype = wp_check_filetype($filename, null);
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_title' => sanitize_file_name($filename),
'post_content' => '',
'post_status' => 'inherit'
);$attach_id = wp_insert_attachment($attachment, $path, $post_id);
require_once(ABSPATH . 'wp-admin/includes/image.php');
$attach_data = wp_generate_attachment_metadata( $attach_id, $path );
wp_update_attachment_metadata( $attach_id, $attach_data );set_post_thumbnail( $post_id, $attach_id );
}}
May 6, 2013 at 4:20 pm #4296AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
- AuthorPosts
- You must be logged in to reply to this topic.