underpin / custom-post-type-loader
Underpin 的自定义文章类型加载器
1.1.0
2021-11-24 21:33 UTC
Requires
- underpin/underpin: ^2.0
This package is auto-updated.
Last update: 2024-08-25 03:54:38 UTC
README
加载器,帮助向 WordPress 网站添加自定义文章类型。
安装
使用 Composer
composer require underpin/custom-post-type-loader
手动安装
此插件使用内置自动加载器,因此只要它在 Underpin 之前被要求,就应该按预期工作。
require_once(__DIR__ . '/underpin-custom-post-type/custom-post-types.php');
设置
- 安装 Underpin。请参阅Underpin 文档
- 根据需要注册新的自定义文章类型菜单。
示例
一个非常基本的示例可能看起来像这样。
// Register custom Post Type underpin()->custom_post_types()->add( 'example_type', [ 'type' => 'example-type', // see register_post_type 'args' => [ /*...*/ ] // see register_post_type ] );
或者,您可以通过扩展 Custom_Post_Type
并直接引用扩展类来实现
underpin()->custom_post_types()->add('custom-post-type-key','Namespace\To\Class');
查询
自定义文章类型实例包括一个名为 query
的方法,它作为 new WP_Query
的包装器。
这封装了此文章类型的查询,并为您提供了重写查询方式的地方,如果您决定扩展此类。
underpin()->custom_post_types()->get( 'post_type' )->query();
编辑文章
与查询类似,自定义文章类型实例包括一个名为 save
的方法,它作为 wp_insert_post
和 wp_update_post
的包装器。它还包括通知记录功能,您可以跟踪请求过程中发生的情况。
这封装了此文章类型的保存操作,并为您提供了重写保存方式的地方,如果您决定扩展此类。
underpin()->custom_post_types()->save( [/* see wp_insert_post */] );
删除文章
这与 save
和 query
的工作方式相同。它包括记录功能,并提供了一种封装操作的方式。
underpin()->custom_post_types()->delete( $id, $force_delete );