PHPackages                             hamworks/wp-post-type - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. hamworks/wp-post-type

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

hamworks/wp-post-type
=====================

0.3.1(2y ago)13.7kGPL-2.0-or-laterPHP

Since Sep 1Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/hamworks/wp-post-type)[ Packagist](https://packagist.org/packages/hamworks/wp-post-type)[ RSS](/packages/hamworks-wp-post-type/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (5)Dependencies (4)Versions (6)Used By (0)

hamworks/wp-post-type
=====================

[](#hamworkswp-post-type)

WordPressのカスタム投稿タイプを簡単に作成するためのライブラリです。

インストール
------

[](#インストール)

```
composer require hamworks/wp-post-type
```

基本的な使い方
-------

[](#基本的な使い方)

```
use HAMWORKS\WP\Post_Type\Builder;

$builder = new Builder( 'book', 'Book' );
$builder->create();
```

詳細設定
----

[](#詳細設定)

### オプションの設定

[](#オプションの設定)

```
$builder = new Builder( 'book', 'Book' );
$builder->set_options(
    [
        'public'        => true,
        'description'   => '書籍の投稿タイプ',
        'has_archive'   => true,
        'hierarchical'  => false,
        'menu_position' => 20,
        'supports'      => [ 'title', 'editor', 'thumbnail', 'excerpt' ],
        'rewrite'       => [
            'slug'       => 'books',
            'with_front' => false,
        ],
    ]
);
$builder->create();
```

### ラベルのカスタマイズ

[](#ラベルのカスタマイズ)

```
$builder = new Builder( 'book', 'Book' );
$builder->set_labels([
    'name'          => 'Books',
    'singular_name' => 'Book',
    'add_new'       => 'Add New Book',
    'add_new_item'  => 'Add New Book',
    'edit_item'     => 'Edit Book',
    'new_item'      => 'New Book',
    'view_item'     => 'View Book',
    'search_items'  => 'Search Books',
]);
$builder->create();
```

デフォルト設定
-------

[](#デフォルト設定)

このライブラリでは以下のデフォルト設定が適用されます：

### 基本設定

[](#基本設定)

- `public`: true
- `show_ui`: true
- `show_in_rest`: true（REST API対応）
- `show_in_admin_bar`: true
- `show_in_nav_menus`: true
- `has_archive`: true
- `hierarchical`: false

### サポート機能

[](#サポート機能)

- title（タイトル）
- author（投稿者）
- editor（エディター）
- excerpt（抜粋）
- revisions（リビジョン）
- thumbnail（アイキャッチ画像）
- custom-fields（カスタムフィールド）

### GraphQL対応

[](#graphql対応)

- WPGraphQL使用時に自動でGraphQLフィールド名を設定
- 単数形と複数形のslugが自動生成される

### URL書き換え

[](#url書き換え)

- Doctrine Inflectorを使用してslugを自動生成
- 複数形のslugが自動設定される（例：`book` → `books`）

### 階層化投稿タイプ

[](#階層化投稿タイプ)

`hierarchical` を `true` に設定すると、自動的に `page-attributes` サポートが追加され、管理画面でのデフォルトソート順が `menu_order` になります。

使用例
---

[](#使用例)

### イベント投稿タイプの作成

[](#イベント投稿タイプの作成)

```
$event_builder = new Builder( 'event', 'イベント' );
$event_builder->set_options([
    'public'        => true,
    'has_archive'   => true,
    'menu_position' => 25,
    'supports'      => [ 'title', 'editor', 'thumbnail', 'custom-fields' ],
    'rewrite'       => [ 'slug' => 'events' ],
]);
$event_builder->create();
```

### 階層化されたページ型投稿タイプの作成

[](#階層化されたページ型投稿タイプの作成)

```
$page_builder = new Builder( 'book', 'Book' );
$page_builder->set_options([
    'hierarchical' => true,  // page-attributesが自動追加される
    'has_archive'  => false,
    'supports'     => [ 'title', 'editor', 'thumbnail' ],
]);
$page_builder->create();
```

メソッド
----

[](#メソッド)

### `__construct( $name, $label )`

[](#__construct-name-label-)

- `$name`: 投稿タイプのスラッグ（単数形で指定）
- `$label`: 表示名

### `set_options( array $args = [] )`

[](#set_options-array-args---)

投稿タイプのオプションを設定します。WordPressの `register_post_type()` と同じ引数を使用できます。

### `set_labels( array $args = [] )`

[](#set_labels-array-args---)

投稿タイプのラベルを設定します。

### `create()`

[](#create)

投稿タイプを登録し、必要なフックを追加します。

### `get_post_type()`

[](#get_post_type)

登録された投稿タイプオブジェクトを返します。

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance39

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~272 days

Total

5

Last Release

1033d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b1738118b1515a2c312e90b71dc041a57a90db61144063f36de6b27587b507d6?d=identicon)[torounit](/maintainers/torounit)

![](https://avatars.githubusercontent.com/u/925303?v=4)[h2ham](/maintainers/h2ham)[@h2ham](https://github.com/h2ham)

![](https://avatars.githubusercontent.com/u/3461188?v=4)[Takenori Okashita (GOUTEN)](/maintainers/gouten5010)[@gouten5010](https://github.com/gouten5010)

---

Top Contributors

[![torounit](https://avatars.githubusercontent.com/u/1908815?v=4)](https://github.com/torounit "torounit (1 commits)")

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/hamworks-wp-post-type/health.svg)

```
[![Health](https://phpackages.com/badges/hamworks-wp-post-type/health.svg)](https://phpackages.com/packages/hamworks-wp-post-type)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

34.8k532.1M19.4k](/packages/laravel-framework)[illuminate/support

The Illuminate Support package.

582110.9M39.8k](/packages/illuminate-support)[symfony/maker-bundle

Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.

3.4k116.2M674](/packages/symfony-maker-bundle)[api-platform/core

Build a fully-featured hypermedia or GraphQL API in minutes!

2.6k50.1M314](/packages/api-platform-core)[tempest/framework

The PHP framework that gets out of your way.

2.2k31.1k12](/packages/tempest-framework)[stoutlogic/acf-builder

An Advanced Custom Field Configuration Builder

8361.9M63](/packages/stoutlogic-acf-builder)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
