Skip to content

Instantly share code, notes, and snippets.

@chrismcintosh
Created January 13, 2024 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrismcintosh/cd31bb6462ecf3a8ecb90aaf67f5da53 to your computer and use it in GitHub Desktop.
Save chrismcintosh/cd31bb6462ecf3a8ecb90aaf67f5da53 to your computer and use it in GitHub Desktop.
Laravel Corcel default post query to trim down irrelevant data
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Corcel\Model\Post as Corcel;
class Post extends Corcel
{
use HasFactory;
protected $connection = 'wordpress';
/**
* Structure WordPress post type to Laravel model
*/
public function newQuery()
{
return parent::newQuery()
->where('post_type', 'post')
->where('post_status', 'publish');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment