joem/saturn
Composer 安装命令:
composer require joem/saturn
包简介
Object-based post-type management in WordPress.
README 文档
README
An object-mapped post type builder & interface for WordPress.
Saturn is a fluent interface used to effortlessly create and manipulate post types and their contents in WordPress.
How Effortlessly? Take a look:
// Provide arguments. $args = array( 'slug' => 'interview', 'singular' => 'Interview', 'plural' => 'Interviews', 'namespace' => 'twentytwenty', ); // Register the post type. $saturn = new Saturn($args); // Run a query, returning 10 posts. $posts = $saturn->query()->limit( 10 )->runQuery();
Saturn is designed to almost act as a model, or resource to represent a post type, this means you can create, delete and change post types through an instance of Saturn, and it's easy peasy.
Not only that, Saturn provides a query engine to interact with post objects (or pages) directly within the instance.
The query builder wraps get_posts, which means everything in get_posts is possible from a saturn instance - with
a beautifully simple interface.
Create an instance
Creating an instance of Saturn is simple:
// Provide arguments. $args = array( 'slug' => 'interview', 'singular' => 'Interview', 'plural' => 'Interviews', 'namespace' => 'twentytwenty', ); // Register the post type. $saturn = new Saturn($args);
Saturn requires an array of parameters, which are used to construct the post type and create the instance:
Parameters
- slug (string) - The slug used to identify the post type.
- singular (string) - The singular name of the post type - human readable, used in labels.
- plural (string) - The plural name of the post type - human readable, used in labels.
- namespace (string) - The text & theme namespace (often referred to as domain) for the text strings.
Instance methods
Methods which are available in an instance of Saturn are detailed below.
instance
Usage
$saturn->instance();
Return
Type: Object WP_Post_Type
An instance of a post type. We do not recommend altering its contents - instead, use Saturn methods. Helpful to quickly access the object.
query
Usage
$saturn->query();
Return
Type: Object Saturn
Used to clear any lingering parameters in the query engine from previous queries. It is important to use this method before setting up queries to prevent any strange or unexpected results.
limit
Parameters
- quantity (int) - The quantity of objects to return for a specified query.
Usage
$saturn->limit( 15 );
Return
Type: Object Saturn
Sets the number of objects to return from a query. The query engine will return the FIRST n matches if specified.
meta
Parameters
-
metaQuery (array) - An array which can contain a single key-value pair, where the key is the meta slug, and the value is the meta value. You can query multiple meta values by instead passing an array of arrays which contain the key-value pair.
-
queryConfig (array) - A list of key-value config items, which would otherwise be provided inside of
meta_query. An example of config item would berelation. Not required.
Usage
Single meta query:
$saturn->query() ->meta( ['name' => 'joe'] ) ->runQuery();
Multiple meta queries:
$saturn->query() ->meta([ ['name' => 'joe'], ['age' => 43]]) ->runQuery();
Multiple meta queries with config:
$saturn->query() ->meta([ ['name' => 'joe'], ['age' => 43]], ['relation' => 'AND']) ->runQuery();
Return
Type: Object Saturn
Sets the meta_query for the query.
tax
Add a tax_query to the query. Parameters
- taxQuery (array) - An array containing a single taxonomy query, to the spec of
WP_Query'stax_queryparameter.
Usage
$saturn->query() ->tax([ 'taxonomy' => 'people', 'field' => 'slug', 'terms' => 'bob', ]) ->runQuery();
joem/saturn 适用场景与选型建议
joem/saturn 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 1, 最近一次更新时间为 2020 年 11 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 joem/saturn 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 joem/saturn 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2020-11-28