Steve Steve - 23 days ago 5
PHP Question

Post not appearing in wordpress site created with laravel

I am using corcel to modify the wordpress content.

Post Model:

<?php
namespace App;

use Corcel\Post as Corcel;

class Post extends Corcel
{
protected $connection = 'wordpress';

}


And in the controller:

public function index()
{
$post=new Post();
$post->post_title="New post";
$post->post_content="This is the post created with laravel.";
$post->save();
}


The new post is created in database. i can see this record in
wp_posts
table in database of wordpress. but the new post is not appearing in wordpress site. what am i missing here?

Also updating the post works fine:

$post=Post::find(3);
$post->post_title="Edited post.";
$post->update();

Answer

You've to set the post_status to published in order to get the post displayed in front-end.

Try after adding $post->post_status="publish";

After updating the method should look like this.

public function index()
{
       $post=new Post();
       $post->post_title="New post";
       $post->post_content="This is the post created with laravel.";
       $post->post_status="publish";
       $post->save();
}