Form to Post – how to connect the form with the categories?

Home Forums Quform WordPress Form to Post – how to connect the form with the categories?

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

    Hello!

    We had a discussion about how to create a post from a form and you really helped me with that. I would like to ask you if you could help me with this.

    After submitting the form field “Categories” (that is checkbox) should automatically create the post draft and check the respectively category name in the default WordPress categories. In the categories field i don’t want to use a custom field as i used in the others.

    Also i have this code for inserting an uploaded image into the feature image but i really want if i can use it to insert it directly into the post and align in to the center.

    Uploaded image code:
    // 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 );
    }

    And this is the code i use to insert the form’s data into the advanced custom fields:
    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_36') . '<br />';
    $content .= 'Κατηγορία διαγωνισμού: ' . $form->getValueHtml('iphorm_1_61') . '<br />';
    $content .= 'Απαιτείτα λογαριασμός Facebook: ' . $form->getValueHtml('iphorm_1_45') . '<br />';
    $content .= 'Συχνότητα διαγωνισμού: ' . $form->getValueHtml('iphorm_1_58') . '<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 />';
    $content .= '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->getValueHtml('iphorm_1_30'));
    add_post_meta($post_id, 'diorganwths_diagwnismou', $form->getValueHtml('iphorm_1_36'));
    add_post_meta($post_id, 'kathgoria_diagwnismou', $form->getValueHtml('iphorm_1_61'));
    add_post_meta($post_id, 'periorismos_perioxhs', $form->getValueHtml('iphorm_1_15'));
    add_post_meta($post_id, 'apaitei_logariasmo_facebook', $form->getValueHtml('iphorm_1_45'));
    add_post_meta($post_id, 'syxnothta_diagwnismou', $form->getValueHtml('iphorm_1_58'));
    add_post_meta($post_id, 'hmeromhnia_lhkshs', $form->getValueHtml('iphorm_1_8'));
    add_post_meta($post_id, 'wra_lhkshs', $form->getValueHtml('iphorm_1_9'));
    add_post_meta($post_id, 'link_diagwnismou', $form->getValueHtml('iphorm_1_11'));
    add_post_meta($post_id, 'oroi_diagwnismou', $form->getValueHtml('iphorm_1_32'));
    add_post_meta($post_id, 'plhrofories_diagwnismou', $form->getValueHtml('iphorm_1_35'));
    add_post_meta($post_id, 'link_diagwnismou', $form->getValueHtml('iphorm_1_11'));

    Please i know that should be a solution to what i want.. Thanks in advance!

    #4601
    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 2 posts - 1 through 2 (of 2 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