[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-8374":3},{"id":4,"name":5,"fullName":6,"owner":5,"repo":5,"description":7,"homepage":8,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":13,"openIssues":14,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":15,"stars7d":15,"stars30d":16,"stars90d":15,"forks30d":15,"starsTrendScore":15,"compositeScore":17,"rankGlobal":9,"rankLanguage":9,"license":18,"archived":19,"fork":19,"defaultBranch":20,"hasWiki":21,"hasPages":19,"topics":22,"createdAt":9,"pushedAt":9,"updatedAt":31,"readmeContent":32,"aiSummary":33,"trendingCount":15,"starSnapshotCount":15,"syncStatus":34,"lastSyncTime":35,"discoverSource":36},8374,"corcel","corcel\u002Fcorcel","Use WordPress backend with Laravel or any PHP application","",null,"PHP",4778,599,149,85,0,3,30.33,"MIT License",false,"9.0",true,[5,23,24,25,26,27,28,29,30],"eloquent","hacktoberfest","laravel","mvc","php","shortcode","taxonomies","wordpress","2026-06-12 02:01:52","\u003Ch1 align=\"center\">\u003Cimg src=\"https:\u002F\u002Fi.imgur.com\u002FfHMqwTF.png\" width=\"170\" alt=\"Corcel PHP\">\u003C\u002Fh1>\n\n**A collection of Model classes that allows you to get data directly from a WordPress database.**\n\n[![Actions Status](https:\u002F\u002Fgithub.com\u002Fcorcel\u002Fcorcel\u002Fworkflows\u002FCI\u002Fbadge.svg)](https:\u002F\u002Fgithub.com\u002Fcorcel\u002Fcorcel\u002Factions)\n[![Packagist](https:\u002F\u002Fimg.shields.io\u002Fpackagist\u002Fv\u002Fjgrossi\u002Fcorcel.svg)](https:\u002F\u002Fpackagist.org\u002Fpackages\u002Fjgrossi\u002Fcorcel)\n[![Packagist](https:\u002F\u002Fimg.shields.io\u002Fpackagist\u002Fdt\u002Fjgrossi\u002Fcorcel.svg)](https:\u002F\u002Fgithub.com\u002Fjgrossi\u002Fcorcel\u002Freleases)\n[![Test Coverage](https:\u002F\u002Fcodeclimate.com\u002Fgithub\u002Fcorcel\u002Fcorcel\u002Fbadges\u002Fcoverage.svg)](https:\u002F\u002Fcodeclimate.com\u002Fgithub\u002Fcorcel\u002Fcorcel\u002Fcoverage)\n[![Maintainability](https:\u002F\u002Fapi.codeclimate.com\u002Fv1\u002Fbadges\u002F3dc8135eee70ae7da325\u002Fmaintainability)](https:\u002F\u002Fcodeclimate.com\u002Fgithub\u002Fcorcel\u002Fcorcel\u002Fmaintainability)\n\nCorcel is a collection of PHP classes built on top of [Eloquent ORM](https:\u002F\u002Flaravel.com\u002Fdocs\u002Fmaster\u002Feloquent) (from [Laravel](http:\u002F\u002Flaravel.com) framework), that provides a fluent interface to connect and get data directly from a [WordPress](http:\u002F\u002Fwordpress.org) database.\n\nYou can use WordPress as the backend (administration panel) or CMS, for inserting posts, custom types, etc, and any other PHP app in the other side querying those data (as a Model layer). It's easier to use Corcel with Laravel, but you're free to use it with any PHP project that uses Composer.\n\n\u003Ca href=\"https:\u002F\u002Fko-fi.com\u002FA36513JF\" target=\"_blank\">Buy me a Coffee\u003C\u002Fa> | \n\u003Ca href=\"https:\u002F\u002Ftwitter.com\u002Fcorcelphp\" target=\"_blank\">Follow Corcel on Twitter\u003C\u002Fa>\n\n# Table of Contents\n# \u003Ca id=\"install\">\u003C\u002Fa> Installing Corcel\n\n\n- [Version Compatibility](#version-compatibility)\n- [Installing Corcel](#installing-corcel)\n- [Database Setup](#database-setup)\n- [Usage](#usage)\n    - [Posts](#posts)\n    - [Advanced Custom Fields (ACF) Integration](#acf)\n    - [Custom Post Type](#custom-post)\n    - [Single Table Inheritance](#single-tab)\n    - [Taxonomies](#taxonomies)\n    - [Post Format](#post-format)\n    - [Pages](#pages)\n    - [Categories & Taxonomies](#cats)\n    - [Attachments & Revision](#attachments)\n    - [Thumbnails](#thumbnails)\n    - [Options](#options)\n    - [Menu](#menu)\n    - [Users](#users)\n    - [Authentication](#auth)\n    - [Running Tests](#tests)\n- [Contributing](#contrib)\n- [License](#license)\n\n# Version Compatibility\n\n Laravel  | Corcel\n:---------|:----------\n 5.1.x    | `~2.1.0`\n 5.2.x    | `~2.2.0`\n 5.3.x    | `~2.3.0`\n 5.4.x    | `~2.4.0`\n 5.5.x    | `~2.5.0`\n 5.6.x    | `~2.6.0`\n 5.7.x    | `~2.7.0`\n 5.8.x    | `~2.8.0`\n 6.0.x    | `^3.0.0`\n 7.0.x    | `^4.0.0`\n 8.0.x    | `^5.0.0`\n 9.0.x    | `^6.0.0`\n 10.0.x   | `^7.0.0`\n 11.0.x   | `^8.0.0`\n 12.0.x   | `^9.0.0`\n\n# \u003Ca id=\"installing-corcel\">\u003C\u002Fa> Installing Corcel\n\nYou need to use Composer to install Corcel into your project:\n\n```\ncomposer require jgrossi\u002Fcorcel\n```\n\n## Configuring (Laravel)\n\n### \u003Ca name=\"config-auto-discovery\">\u003C\u002Fa> Laravel 5.5 and newer\n\nCorcel wil register itself using Laravel's [Auto Discovery](https:\u002F\u002Flaravel.com\u002Fdocs\u002F5.5\u002Fpackages#package-discovery).\n\n### \u003Ca name=\"config-service-loader\">\u003C\u002Fa> Laravel 5.4 and older\n\nYou'll have to include `CorcelServiceProvider` in your `config\u002Fapp.php`:\n\n```php\n'providers' => [\n    \u002F*\n     * Package Service Providers...\n     *\u002F\n    Corcel\\Laravel\\CorcelServiceProvider::class,\n]\n```\n\n### \u003Ca name=\"config-publish\">\u003C\u002Fa> Publishing the configuration file\n\nNow configure our config file to make sure your database is set correctly and to allow you to register custom post types and shortcodes in a very easy way:\n\nRun the following Artisan command in your terminal:\n\n```\nphp artisan vendor:publish --provider=\"Corcel\\Laravel\\CorcelServiceProvider\"\n```\n\nNow you have a `config\u002Fcorcel.php` config file, where you can set the database connection with WordPress tables and much more.\n\n# \u003Ca id=\"database-setup\">\u003C\u002Fa> Database Setup\n\n## Laravel Setup\n\nJust set the database `connection` you want to be used by Corcel in `config\u002Fcorcel.php`.\n\nLet' suppose you have those following database connections in your `config\u002Fdatabase.php` file:\n\n```php\n\u002F\u002F File: \u002Fconfig\u002Fdatabase.php\n\n'connections' => [\n\n    'mysql' => [ \u002F\u002F for Laravel database\n        'driver'    => 'mysql',\n        'host'      => 'localhost',\n        'database'  => 'mydatabase',\n        'username'  => 'admin'\n        'password'  => 'secret',\n        'charset'   => 'utf8',\n        'collation' => 'utf8_unicode_ci',\n        'prefix'    => '',\n        'strict'    => false,\n        'engine'    => null,\n    ],\n\n    'wordpress' => [ \u002F\u002F for WordPress database (used by Corcel)\n        'driver'    => 'mysql',\n        'host'      => 'localhost',\n        'database'  => 'mydatabase',\n        'username'  => 'admin',\n        'password'  => 'secret',\n        'charset'   => 'utf8',\n        'collation' => 'utf8_unicode_ci',\n        'prefix'    => 'wp_',\n        'strict'    => false,\n        'engine'    => null,\n    ],\n],\n```\n\nIn this case you should want to use the `wordpress` connection for Corcel, so just set it into the Corcel config file `config\u002Fcorcel.php`:\n\n```php\n'connection' => 'wordpress',\n```\n\n## Other PHP Framework (not Laravel) Setup\n\nHere you have to configure the database to fit the Corcel requirements. First, you should include the Composer `autoload` file if not already loaded:\n\n```php\nrequire __DIR__ . '\u002Fvendor\u002Fautoload.php';\n```\n\nNow you must set your WordPress database params:\n\n```php\n$params = [\n    'database'  => 'database_name',\n    'username'  => 'username',\n    'password'  => 'pa$$word',\n    'prefix'    => 'wp_' \u002F\u002F default prefix is 'wp_', you can change to your own prefix\n];\nCorcel\\Database::connect($params);\n```\n\nYou can specify all Eloquent params, but some are default (but you can override them).\n\n```php\n'driver'    => 'mysql',\n'host'      => 'localhost',\n'charset'   => 'utf8',\n'collation' => 'utf8_unicode_ci',\n'prefix'    => 'wp_', \u002F\u002F Specify the prefix for WordPress tables, default prefix is 'wp_'\n```\n\n# \u003Ca id=\"usage\">\u003C\u002Fa>  Usage\n\n## \u003Ca id=\"posts\">\u003C\u002Fa> Posts\n\n> Every time you see `Post::method()`, if you're using your own Post class (where you set the connection name), like `App\\Post` you should use `App\\Post::method()` and not `Post::method()`. All the examples are assuming you already know this difference.\n\n> In the examples, every time you see `Post::method()` assume `Corcel\\Model\\Post::method()`.\n\n```php\n\u002F\u002F All published posts\n$posts = Post::published()->get();\n$posts = Post::status('publish')->get();\n\n\u002F\u002F A specific post\n$post = Post::find(31);\necho $post->post_title;\n```\n\n## Creating your own model classes\n\nOptionally you can create your own `Post` model (or Page, or whatever) which extends `Corcel\\Post`. Then set the connection name (if you want to override the Corcel's default one) you're using, in this case `foo-bar`:\n\n> Extending `Corcel\\Model\\Post` class can add flexibility to your project, once you can add custom methods and logic, according what you need to use from your WordPress database.\n\n```php\n\u003C?php \u002F\u002F File: app\u002FPost.php\n\nnamespace App;\n\nuse Corcel\\Model\\Post as Corcel;\n\nclass Post extends Corcel\n{\n    protected $connection = 'foo-bar';\n\n    public function customMethod() {\n        \u002F\u002F\n    }\n}\n```\n\nSo, now you can fetch WP database data using your own class:\n\n```php\n$posts = App\\Post::all(); \u002F\u002F using the 'foo-bar' connection\n```\n\n> Just remember you don't have to extends our `Post` class, you can use `Corcel\\Model\\Post` and all others model without any problem.\n\n### Meta Data (Custom Fields)\n\n> NOTE: In Corcel v1 you could save meta data using the `Post::save()` method. That's not allowed anymore. Use `saveMeta()` or `createMeta()` (see below) methods to save post meta.\n\nYou can retrieve meta data from posts too.\n\n```php\n\u002F\u002F Get a custom meta value (like 'link' or whatever) from a post (any type)\n$post = Post::find(31);\necho $post->meta->link; \u002F\u002F OR\necho $post->fields->link;\necho $post->link; \u002F\u002F OR\n```\n\nTo create or update meta data form a User just use the `saveMeta()` or `saveField()` methods. They return `bool` like the Eloquent `save()` method.\n\n```php\n$post = Post::find(1);\n$post->saveMeta('username', 'jgrossi');\n```\n\nYou can save many meta data at the same time too:\n\n```php\n$post = Post::find(1);\n$post->saveMeta([\n    'username' => 'jgrossi',\n    'url' => 'http:\u002F\u002Fjgrossi.com',\n]);\n```\n\nYou also have the `createMeta()` and `createField()` methods, that work like the `saveX()` methods, but they are used only for creation and return the `PostMeta` created instance, instead of `bool`.\n\n```php\n$post = Post::find(1);\n$postMeta = $post->createMeta('foo', 'bar'); \u002F\u002F instance of PostMeta class\n$trueOrFalse = $post->saveMeta('foo', 'baz'); \u002F\u002F boolean\n```\n\n### Querying Posts by Custom Fields (Meta)\n\nThere are multiples possibilities to query posts by their custom fields (meta) by using scopes on a `Post` (or another other model which uses the `HasMetaFields` trait) class:\n\nTo check if a meta key exists, use the `hasMeta()` scope:\n```\n\u002F\u002F Finds a published post with a meta flag.\n$post = Post::published()->hasMeta('featured_article')->first();\n```\n\nIf you want to precisely match a meta-field, you can use the `hasMeta()` scope with a value.\n\n```php\n\u002F\u002F Find a published post which matches both meta_key and meta_value.\n$post = Post::published()->hasMeta('username', 'jgrossi')->first();\n```\n\nIf you need to match multiple meta-fields, you can also use the `hasMeta()` scope passing an array as parameter:\n\n```php\n$post = Post::hasMeta(['username' => 'jgrossi'])->first();\n$post = Post::hasMeta(['username' => 'jgrossi', 'url' => 'jgrossi.com'])->first();\n\u002F\u002F Or just passing the keys\n$post = Post::hasMeta(['username', 'url'])->first();\n```\n\nIf you need to match a case-insensitive string, or match with wildcards, you can use the `hasMetaLike()` scope with a value. This uses an SQL `LIKE` operator, so use '%' as a wildcard operator.\n\n```php\n\u002F\u002F Will match: 'J Grossi', 'J GROSSI', and 'j grossi'.\n$post = Post::published()->hasMetaLike('author', 'J GROSSI')->first();\n\n\u002F\u002F Using % as a wildcard will match: 'J Grossi', 'J GROSSI', 'j grossi', 'Junior Grossi' etc.\n$post = Post::published()->hasMetaLike('author', 'J%GROSSI')->first();\n```\n\n### Fields Aliases\n\nThe `Post` class has support to \"aliases\", so if you check the `Post` class you should note some aliases defined in the static `$aliases` array, like `title` for `post_title` and `content` for `post_content`.\n\n```php\n$post = Post::find(1);\n$post->title === $post->post_title; \u002F\u002F true\n```\n\nIf you're extending the `Post` class to create your own class you can use `$aliases` too. Just add new aliases to that static property inside your own class and it will automatically inherit all aliases from parent `Post` class:\n\n```php\nclass A extends \\Corcel\\Post\n{\n    protected static $aliases = [\n        'foo' => 'post_foo',\n    ];\n}\n\n$a = A::find(1);\necho $a->foo;\necho $a->title; \u002F\u002F from Post class\n```\n\n### Custom Scopes\n\nTo order posts you can use `newest()` and `oldest()` scopes, for both `Post` and `User` classes:\n\n```php\n$newest = Post::newest()->first();\n$oldest = Post::oldest()->first();\n```\n\n### Pagination\n\nTo order posts just use Eloquent `paginate()` method:\n\n```php\n$posts = Post::published()->paginate(5);\nforeach ($posts as $post) {\n    \u002F\u002F ...\n}\n```\n\nTo display the pagination links just call the `links()` method:\n\n ```php\n {{ $posts->links() }}\n ```\n\n## \u003Ca id=\"acf\">\u003C\u002Fa>  Advanced Custom Fields (ACF)\n\nIf you want to retrieve a custom field created by the [Advanced Custom Fields (ACF)](http:\u002F\u002Fadvancedcustomfields.com) plugin, you have to install the `corcel\u002Facf` plugin - [click here for more information](http:\u002F\u002Fgithub.com\u002Fcorcel\u002Facf) - and call the custom field like this:\n\n```php\n$post = Post::find(123);\necho $post->acf->some_radio_field;\n$repeaterFields = $post->acf->my_repeater_name;\n```\n\nTo avoid unnecessary SQL queries just set the field type you're requesting. Usually two SQL queries are necessary to get the field type, so if you want to specify it you're skipping those extra queries:\n\n```php\n$post = Post::find(123);\necho $post->acf->text('text_field_name');\necho $post->acf->boolean('boolean_field_name');\n```\n\n## \u003Ca id=\"custom-post\">\u003C\u002Fa> Custom Post Type\n\nYou can work with custom post types too. You can use the `type(string)` method or create your own class.\n\n```php\n\u002F\u002F using type() method\n$videos = Post::type('video')->status('publish')->get();\n\n\u002F\u002F using your own class\nclass Video extends Corcel\\Post\n{\n    protected $postType = 'video';\n}\n$videos = Video::status('publish')->get();\n```\n\nUsing `type()` method will make Corcel to return all objects as `Corcel\\Post`. Using your custom class you have the advantage to customize classes, including custom methods and properties, return all objects as `Video`, for example.\n\nCustom post types and meta data:\n\n```php\n\u002F\u002F Get 3 posts with custom post type (store) and show its address\n$stores = Post::type('store')->status('publish')->take(3)->get();\nforeach ($stores as $store) {\n    $storeAddress = $store->address; \u002F\u002F option 1\n    $storeAddress = $store->meta->address; \u002F\u002F option 2\n    $storeAddress = $store->fields->address; \u002F\u002F option 3\n}\n```\n\n### Configuring the returning Instance\n\nEvery time you call something like `Post::type('video)->first()` or `Video::first()` you receive a `Corcel\\Model\\Post` instance.\n\nIf you choose to create a new class for your custom post type, you can have this class be returned for all instances of that post type.\n\n#### Registering Post Types (the easy way)\n\nInstead of call `Post::registerPostType()` method for all custom post type you want to register, just use the Corcel's config file and map all custom posts and it's classes. They will be registered automatically for you:\n\n```php\n'post_types' => [\n    'video' => App\\Video::class,\n    'foo' => App\\Foo::class,\n]\n```\n\nSo every time you query a custom post type the mapped instance will be returned.\n\n> This is particular useful when you are intending to get a Collection of Posts of different types (e.g. when fetching the posts defined in a menu).\n\n#### Registering Post Types (the hard way)\n\n```php\n\u002F\u002Fall objects in the $videos Collection will be instances of Post\n$videos = Post::type('video')->status('publish')->get();\n\n\u002F\u002F register the video custom post type and its particular class\nPost::registerPostType('video', '\\App\\Video')\n\n\n\u002F\u002Fnow all objects in the $videos Collection will be instances of Video\n$videos = Post::type('video')->status('publish')->get();\n```\n\nYou can also do this for inbuilt classes, such as Page or Post. Simply register the Page or Post class with the associated post type string, and that object will be returned instead of the default one.\n\n## \u003Ca id=\"shortcodes\">\u003C\u002Fa> Shortcodes\n\n### From config (Laravel)\n\nYou can map all shortcodes you want inside the `config\u002Fcorcel.php` file, under the `'shortcodes'` key. In this case you should create your own class that `implements` the `Corcel\\Shortcode` interface, that requires a `render()` method:\n\n```php\n'shortcodes' => [\n    'foo' => App\\Shortcodes\\FooShortcode::class,\n    'bar' => App\\Shortcodes\\BarShortcode::class,\n],\n```\n\nThis is a sample shortcode class:\n\n```php\nclass FakeShortcode implements \\Corcel\\Shortcode\n{\n    \u002F**\n     * @param ShortcodeInterface $shortcode\n     * @return string\n     *\u002F\n    public function render(ShortcodeInterface $shortcode)\n    {\n        return sprintf(\n            'html-for-shortcode-%s-%s',\n            $shortcode->getName(),\n            $shortcode->getParameter('one')\n        );\n    }\n}\n```\n\n### In runtime\n\nYou can add [shortcodes](https:\u002F\u002Fcodex.wordpress.org\u002FShortcode_API) by calling the `addShortcode` method on the `Post` model :\n\n```php\n\u002F\u002F [gallery id=\"1\"]\nPost::addShortcode('gallery', function ($shortcode) {\n    return $shortcode->getName() . '.' . $shortcode->getParameter('id');\n});\n$post = Post::find(1);\necho $post->content;\n```\n\n> Laravel 5.5 uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider\n\nIf you are using Laravel, we suggest adding your shortcodes handlers in `App\\Providers\\AppServiceProvider`, in the `boot` method.\n\n### Shortcode Parsing\n\nShortcodes are parsed with the [*thunderer\u002Fshortcode*](https:\u002F\u002Fgithub.com\u002Fthunderer\u002FShortcode) library. \n\nSeveral different parsers are provided. `RegularParser` is the most technically correct and is provided by default. This is suitable for most cases. However if you encounter some irregularities in your shortcode parsing, you may need to configure Corcel to use the `WordpressParser`, which more faithfully matches WordPress' shortcode regex. To do this, if you are using Laravel, edit the `config\u002Fcorcel.php` file, and uncomment your preferred parser. Alternatively, you can replace this with a parser of your own.\n\n```php\n'shortcode_parser' => Thunder\\Shortcode\\Parser\\RegularParser::class,\n\u002F\u002F 'shortcode_parser' => Thunder\\Shortcode\\Parser\\WordpressParser::class,\n```\n\nIf you are not using Laravel, you can to do this in runtime, calling the `setShortcodeParser()` method from any class which uses the `Shortcodes` trait, such as `Post`, for example.\n\n```php\n$post->setShortcodeParser(new WordpressParser());\necho $post->content; \u002F\u002F content parsed with \"WordpressParser\" class\n```\n\nFor more information about the shortcode package, [click here](https:\u002F\u002Fgithub.com\u002Fthunderer\u002FShortcode).\n\n## \u003Ca id=\"taxonomies\">\u003C\u002Fa>Taxonomies\n\nYou can get taxonomies for a specific post like:\n\n```php\n$post = Post::find(1);\n$taxonomy = $post->taxonomies()->first();\necho $taxonomy->taxonomy;\n```\n\nOr you can search for posts using its taxonomies:\n\n```php\n$post = Post::taxonomy('category', 'php')->first();\n```\n\n## \u003Ca id=\"post-format\">\u003C\u002Fa>Post Format\n\nYou can also get the post format, like the WordPress function `get_post_format()`:\n\n```php\necho $post->getFormat(); \u002F\u002F should return something like 'video', etc\n```\n\n## \u003Ca id=\"pages\">\u003C\u002Fa>Pages\n\nPages are like custom post types. You can use `Post::type('page')` or the `Corcel\\Model\\Page` class.\n\n```php\n\nuse Corcel\\Model\\Page;\n\n\u002F\u002F Find a page by slug\n$page = Page::slug('about')->first(); \u002F\u002F OR\n$page = Post::type('page')->slug('about')->first();\necho $page->post_title;\n```\n\n## \u003Ca id=\"cats\">\u003C\u002Fa>Categories and Taxonomies\n\nGet a category or taxonomy or load posts from a certain category. There are multiple ways\nto achieve it.\n\n```php\n\u002F\u002F all categories\n$cat = Taxonomy::category()->slug('uncategorized')->posts->first();\necho \"\u003Cpre>\"; print_r($cat->name); echo \"\u003C\u002Fpre>\";\n\n\u002F\u002F only all categories and posts connected with it\n$cat = Taxonomy::where('taxonomy', 'category')->with('posts')->get();\n$cat->each(function($category) {\n    echo $category->name;\n});\n\n\u002F\u002F clean and simple all posts from a category\n$cat = Category::slug('uncategorized')->posts->first();\n$cat->posts->each(function($post) {\n    echo $post->post_title;\n});\n```\n\n## \u003Ca id=\"attachments\">\u003C\u002Fa>Attachment and Revision\n\nGetting the attachment and\u002For revision from a `Post` or `Page`.\n\n```php\n$page = Page::slug('about')->with('attachment')->first();\n\u002F\u002F get feature image from page or post\nprint_r($page->attachment);\n\n$post = Post::slug('test')->with('revision')->first();\n\u002F\u002F get all revisions from a post or page\nprint_r($post->revision);\n```\n\n## \u003Ca id=\"thumbnails\">\u003C\u002Fa>Thumbnails\n\nGetting the thumbnail for a `Post` or `Page`.\n\n```php\n$post = Post::find(1);\n\n\u002F\u002F Retrieve an instance of Corcel\\Model\\Meta\\ThumbnailMeta.\nprint_r($post->thumbnail);\n\n\u002F\u002F For convenience you may also echo the thumbnail instance to get the URL of the original image.\necho $post->thumbnail;\n```\n\nTo retrieve a particular thumbnail size you may call the `->size()` method on the thumbnail object and pass in a thumbnail size string parameter (e.g. `thumbnail` or `medium`). If the thumbnail has been generated, this method returns an array of image metadata, otherwise the original image URL will be returned as a fallback.\n\n```php\nif ($post->thumbnail !== null) {\n    \u002F**\n     * [\n     *     'file' => 'filename-300x300.jpg',\n     *     'width' => 300,\n     *     'height' => 300,\n     *     'mime-type' => 'image\u002Fjpeg',\n     *     'url' => 'http:\u002F\u002Flocalhost\u002Fwp-content\u002Fuploads\u002Ffilename-300x300.jpg',\n     * ]\n     *\u002F\n    print_r($post->thumbnail->size(Corcel\\Model\\Meta\\ThumbnailMeta::SIZE_THUMBNAIL));\n\n    \u002F\u002F http:\u002F\u002Flocalhost\u002Fwp-content\u002Fuploads\u002Ffilename.jpg\n    print_r($post->thumbnail->size('invalid_size'));\n}\n```\n\n## \u003Ca id=\"options\">\u003C\u002Fa>Options\n\n> In previous versions of Corcel this classe was called `Options` instead of `Option` (singular). So take care of using always this class in the singular form starting from `v2.0.0`.\n\n> The `Option::getAll()` method was removed in Corcel 2+, in favor of `Option::asArray($keys [])`.\n\nYou can use the `Option` class to get data from `wp_options` table:\n\n```php\n$siteUrl = Option::get('siteurl');\n```\n\nYou can also add new options:\n\n```php\nOption::add('foo', 'bar'); \u002F\u002F stored as string\nOption::add('baz', ['one' => 'two']); \u002F\u002F this will be serialized and saved\n```\n\nYou can get all options in a simple array:\n\n```php\n$options = Option::asArray();\necho $options['siteurl'];\n```\n\nOr you can specify only the keys you want to get:\n\n```php\n$options = Option::asArray(['siteurl', 'home', 'blogname']);\necho $options['home'];\n```\n\n## \u003Ca id=\"menu\">\u003C\u002Fa> Menu\n\nTo get a menu by its slug, use the syntax below. The menu items will be loaded in the `items` variable (it's a collection of `Corcel\\Model\\MenuItem` objects).\n\nThe currently supported menu items are: Pages, Posts, Custom Links and Categories.\n\nOnce you'll have instances of `MenuItem` class, if you want to use the original instance (like the original Page or Term, for example), just call the `MenuItem::instance()` method. The `MenuItem` object is just a post with `post_type` equals `nav_menu_item`:\n\n```php\n$menu = Menu::slug('primary')->first();\n\nforeach ($menu->items as $item) {\n    echo $item->instance()->title; \u002F\u002F if it's a Post\n    echo $item->instance()->name; \u002F\u002F if it's a Term\n    echo $item->instance()->link_text; \u002F\u002F if it's a custom link\n}\n```\n\nThe `instance()` method will return the matching object:\n\n- `Post` instance for `post` menu item;\n- `Page` instance for `page` menu item;\n- `CustomLink` instance for `custom` menu item;\n- `Term` instance for `category` menu item.\n\n### Multi-levels Menus\n\nTo handle multi-levels menus, loop through all the menu items to put them on the right levels, for example.\n\nYou can use the `MenuItem::parent()` method to retrieve the parent instance of that menu item:\n\n```php\n$items = Menu::slug('foo')->first()->items;\n$parent = $items->first()->parent(); \u002F\u002F Post, Page, CustomLink or Term (category)\n```\n\nTo group menu items according their parents, you can use the `->groupBy()` method in the `$menu->items` collection, grouping menu items by their `$item->parent()->ID`.\n\nTo read more about the `groupBy()` method [take a look on the Laravel documentation](https:\u002F\u002Flaravel.com\u002Fdocs\u002F5.4\u002Fcollections#method-groupby).\n\n## \u003Ca id=\"users\">\u003C\u002Fa> Users\n\nYou can manipulate users in the same manner you work with posts:\n\n```php\n\u002F\u002F All users\n$users = User::get();\n\n\u002F\u002F A specific user\n$user = User::find(1);\necho $user->user_login;\n```\n\n## \u003Ca id=\"auth\">\u003C\u002Fa>Authentication\n\n### Using Laravel\n\nIf you're using Laravel 5.4 or older, make sure you have the [`CorcelServiceProvider` provider registered](#config-service-loader).\n\nAnd then, define the user provider in `config\u002Fauth.php` to allow Laravel to login with WordPress users:\n\n```php\n'providers' => [\n    'users' => [\n        'driver' => 'corcel',\n        'model'  => Corcel\\Model\\User::class,\n    ],\n],\n```\n\nNow you can use the `Auth` facade to authenticate users:\n\n```php\nAuth::validate([\n    'email' => 'admin@example.com', \u002F\u002F or using 'username' too\n    'password' => 'secret',\n]);\n```\n\nTo make Laravel's Password Reset work with Corcel, we have to override how passwords are stored in the database. To do this, you must change `Auth\u002FPasswordController.php` from:\n\n```php\nuse App\\Http\\Controllers\\Controller;\nuse Illuminate\\Foundation\\Auth\\ResetsPasswords;\n\nclass PasswordController extends Controller\n{\n    use ResetsPasswords;\n```\n\nto\n\n```php\nuse App\\Http\\Controllers\\Controller;\nuse Illuminate\\Foundation\\Auth\\ResetsPasswords;\nuse Corcel\\Laravel\\Auth\\ResetsPasswords as CorcelResetsPasswords;\n\nclass PasswordController extends Controller\n{\n    use ResetsPasswords, CorcelResetsPasswords {\n        CorcelResetsPasswords::resetPassword insteadof ResetsPasswords;\n    }\n```\n\n### Not using Laravel\n\nYou can use the `AuthUserProvider` class to manually authenticate a user :\n\n```php\n$userProvider = new Corcel\\Laravel\\Auth\\AuthUserProvider;\n$user = $userProvider->retrieveByCredentials(['username' => 'admin']);\nif(!is_null($user) && $userProvider->validateCredentials($user, ['password' => 'admin'])) {\n    \u002F\u002F successfully login\n}\n```\n\n> Remember you can use both `username` and `email` as credentials for a User.\n\n# \u003Ca id=\"tests\">\u003C\u002Fa> Running Tests\n\nTo run the phpunit tests, execute the following command :\n\n```\n.\u002Fvendor\u002Fbin\u002Fphpunit\n```\n\nIf you have the global `phpunit` command installed you can just type:\n\n```\nphpunit\n```\n\nAll tests were written using Sqlite with `:memory` database, so it runs in your memory. All tests use `factories` and `migrations`. Take a look on `tests\u002Fdatabase\u002Ffactories` and `tests\u002Fdatabase\u002Fmigrations` directories for more information.\n\n# \u003Ca id=\"contrib\">\u003C\u002Fa> Contributing\n\nAll contributions are welcome to help improve Corcel.\n\nBefore you submit your Pull Request (PR) consider the following guidelines:\n\n- Fork https:\u002F\u002Fgithub.com\u002Fcorcel\u002Fcorcel in Github;\n\n- Clone your forked repository (not Corcel's) locally and create your own branch based on the version you want to fix (`2.1`, `2.2`, `2.3`, `2.4` or `2.5`): `git checkout -b my-fix-branch 2.5`;\n\n- Make all code changes. Remember here to write at least one test case for any feature you add or any bugfix (if it's not tested yet). Our goal is to have 100% of the code covered by tests, so help us to write a better code ;-) If you don' have experience with tests it's a good opportunity to learn. Just take a look into our tests cases and you'll see how simple they are.\n\n- Run the unit tests locally to make sure your changes did not break any other piece of code;\n\n- Push your new branch to your forked repository, usually `git push origin HEAD` should work;\n\n- In GitHub again, create a Pull Request (PR) from your custom `my-fix-branch` branch (from your forked repository) to the related branch (`corcel:2.5`, for example, not `corcel:master`, please;\n\n- Wait for the approval :-)\n\n## \u003Ca id=\"license\">\u003C\u002Fa> Licence\n\n[MIT License](http:\u002F\u002Fjgrossi.mit-license.org\u002F) © Junior Grossi\n","Corcel 是一个允许你直接从 WordPress 数据库获取数据的 PHP 类集合。它基于 Laravel 的 Eloquent ORM 构建，提供了一个流畅的接口来连接和查询 WordPress 数据库。主要功能包括支持文章、自定义类型、分类法等，并且可以与 Laravel 或任何使用 Composer 的 PHP 项目无缝集成。适合于需要利用现有 WordPress 后端作为内容管理系统，同时希望在前端应用中灵活地处理这些内容的场景。通过 Corcel，开发者能够轻松地将 WordPress 丰富的管理功能与现代 PHP 框架的强大能力结合起来。",2,"2026-06-11 03:17:37","top_language"]