How to automatically create a post?

Home Forums Quform WordPress How to automatically create a post?

This topic is: not resolved
Viewing 15 posts - 1 through 15 (of 19 total)
  • Author
    Posts
  • #4128
    haritos
    Participant

    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?

    #4129
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #4130
    haritos
    Participant

    Yes 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?

    #4131
    haritos
    Participant

    Also 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!

    #4132
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #4133
    haritos
    Participant

    I tried to find our conversation but i can’t! If you could sent it me i would appreciate it! Thank you!

    #4136
    haritos
    Participant

    Hey Ally,

    Can you send me our past conversation?

    anonymos-ptp@hotmail.com

    #4143
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #4157
    haritos
    Participant

    Yes i saw it!

    Thank you!

    #4217
    haritos
    Participant

    Hey 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!

    #4233
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #4248
    haritos
    Participant

    Hi 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?

    #4270
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #4288
    haritos
    Participant

    Thanks 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 );
    }

    }

    #4296
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

Viewing 15 posts - 1 through 15 (of 19 total)
  • You must be logged in to reply to this topic.
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy