vincentts/wp-models
最新稳定版本:0.2
Composer 安装命令:
composer require vincentts/wp-models
包简介
Wrapper models around WP_Query
README 文档
README
Wrapper class around WP Query to create models.
Installations
Install the package through composer by running composer require "vincentts/wp-models".
Getting Started
Define model classes by extending PostModel or TermModel.
Post Model
namespace Models; use Vincentts\WpModels\PostModel; class Post extends PostModel { protected $post_type = 'post'; }
Term Model
namespace Models; use Vincentts\WpModels\TermModel; class Category extends TermModel { protected $taxonomy = 'category'; }
Defining relationships
namespace Models; use Vincentts\WpModels\PostModel; use Models\Category; class Post extends PostModel { protected $post_type = 'post'; public function categories() { return $this->has( Category::class ); } }
Usage
Getting posts with relationships
use Models\Post; $posts = (new Post())->with(['categories'])->get();
Including meta data
Note ACF
get_fieldwill be used if it exists. Otherwise it will useget_post_meta.
use Models\Post; $posts = (new Post())->meta(['summary', 'description'])->with(['categories'])->get();
There are also other methods similar to the arguments from WP_Query.
统计信息
- 总下载量: 42
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-02-05