Home › Forums › Quform WordPress › Attaching uploaded file as a thumbnail after creation a post from quform
- This topic has 3 replies, 2 voices, and was last updated 6 years, 8 months ago by Allan.
- AuthorPosts
- July 27, 2017 at 9:53 am #21529cybermaestroParticipant
Hello. I’m creating a post from quform acodring provided instructions here. Еverything works just fine, but image is not attached to newly created post as a thumbnail. It goes to Mediafiles, but remains not attached to the post. Could you please look at my code?
function my_create_wp_post($form) { $title = $form->getValue('iphorm_9_1'); $rauthor = $form->getValue('iphorm_9_8'); ob_start(); include dirname(__FILE__) . '/form-post.php'; $content = ob_get_clean(); $post = array( 'post_title' => $title, 'post_content' => $content, 'post_type' => 'reviews', 'meta_input' => array( 'eg-avtor' => $rauthor // record autor of the reviwew to my custom meta field ), ); wp_insert_post($post); // Add attachments $file = $form->getValue('iphorm_9_3'); if (isset($file[0])) { $file = $file[0]; $filename = $file['text']; $path = $file['fullPath']; $wp_filetype = wp_check_filetype($filename, null ); $attachment = array( 'guid' => $file['url'], 'post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\.[^.]+$/', '', $filename), 'post_content' => '', 'post_status' => 'inherit' ); $attach_id = wp_insert_attachment($attachment, $path, $postId); 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($postId, $attach_id); } } add_action('iphorm_post_process_9', 'my_create_wp_post', 9, 1);
- This topic was modified 6 years, 8 months ago by cybermaestro.
- This topic was modified 6 years, 8 months ago by cybermaestro.
July 27, 2017 at 11:00 am #21532cybermaestroParticipantHere is a message from debug log:
[27-Jul-2017 09:58:11 UTC] PHP Notice: Undefined variable: postId in /home/wm38668/domains/iis-berlin.ru/public_html/wp-content/themes/iis-theme/functions.php on line 229
[27-Jul-2017 09:58:11 UTC] PHP Notice: Undefined variable: postId in /home/wm38668/domains/iis-berlin.ru/public_html/wp-content/themes/iis-theme/functions.php on line 235
July 27, 2017 at 11:16 am #21533cybermaestroParticipantfound it by myself. Undefined variable.
July 30, 2017 at 6:55 am #21545AllanSupport 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.