Attaching uploaded file as a thumbnail after creation a post from quform

Home Forums Quform WordPress Attaching uploaded file as a thumbnail after creation a post from quform

This topic is: not resolved
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #21529
    cybermaestro
    Participant

    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.
    #21532
    cybermaestro
    Participant

    Here 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

    #21533
    cybermaestro
    Participant

    found it by myself. Undefined variable.

    #21545
    Allan
    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 4 posts - 1 through 4 (of 4 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