Corcel - Set featured image for saved post

553 views Asked by At

I am using "jgrossi/corcel": "3.0.0", Laravel 6.16.0 and PHP 7.4.1

I would like to add a featured image to my saved()-post

I tried to create a wordpress post the following way:

        $post = new Post();
        $post->post_title = $title;
        $post->post_content = $msg;
        $post->image = "http://www.urlToImage.com/image.png"; //does not work
        $post->save();

When trying the above function I get the following exception:

Column not found: 1054 Unknown column 'image' in 'field list' (SQL: insert into `wp_posts` (`post_title`, `post_content`, `post_type`, `post_status`, `ping_status`, `post_author`, `image`, `post_modified_gmt`, `post_modified`, `post_date_gmt`, `post_date`)

Any suggestions how to save a post and set the featured image?

Appreciate your replies!

1

There are 1 answers

0
Aaron Katema On

i solved it using the following method

$post = Post::create([
            'post_title'=>$request->input('title'),
            'post_content' => $request->input('content'),
            'post_status'=>'publish',
            "post_type" => "post"
        ]);
     
        PostMeta::create([
            'post_id'=>$post->ID,
            'meta_key'=>'_thumbnail_ext_url',
            'meta_value'=>$image
        ]);

to use external url for a post i installed this plugin https://wordpress.org/plugins/external-url-as-post-featured-image-thumbnail/?