PHPackages                             hanamura/wp-model - 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. hanamura/wp-model

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

hanamura/wp-model
=================

Missing functionalities from model objects of WordPress.

1.2.1(7mo ago)74.6kMITPHPPHP &gt;=5.3.0

Since Jan 28Pushed 7mo ago1 watchersCompare

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

READMEChangelogDependenciesVersions (8)Used By (0)

wp-model
========

[](#wp-model)

Missing functionalities from model objects of WordPress.

API
---

[](#api)

### Post

[](#post)

Extended wrapper of native post object of WordPress, [`WP_Post`](http://codex.wordpress.org/Class_Reference/WP_Post).

#### new Post($post), Post::create($post)

[](#new-postpost-postcreatepost)

- **$post** *integer | WP\_Post*
    Post id or WP\_Post object.

```
$post = new WPModel\Post($post_id);

// same properties of WP_Post are accessible
echo $post->post_date;
echo $post->post_title;
echo $post->post_mime_type;
```

#### -&gt;permalink, -&gt;permalink()

[](#-permalink--permalink)

Get permalink of the post.

**Returns**: *string*

```
$post = new WPModel\Post($post_id);

echo $post->permalink;
```

#### -&gt;children, -&gt;children(\[$options\])

[](#-children--childrenoptions)

Get child posts of the post.

- **$options** *array*
    - **$options\['id'\]** *integer | array*
        Filter by ids.
    - **$options\['post\_type'\]** *string | array*
        Filter by post types.
    - **$options\['post\_mime\_type'\]** *string | array*
        Filter by post mime types.

**Returns**: *array*

```
$post = new WPModel\Post($post_id);

$children = $post->children(array(
  'id' => array(10, 11, 12)
));
$attachments = $post->children(array(
  'post_type' => 'attachment'
));
$images = $post->children(array(
  'post_mime_type' => 'image'
));
```

#### -&gt;terms, -&gt;terms(\[$options\])

[](#-terms--termsoptions)

Get terms attached to the post.

- **$options** *array*
    - **$options\['taxonomy'\]** *string*
        Specify taxonomy. Default value: `'category'`

**Returns**: *array*

```
$post = new WPModel\Post($post_id);

$custom_terms = $post->terms(array(
  'taxonomy' => 'custom_taxonomy'
));
```

#### -&gt;meta, -&gt;meta()

[](#-meta--meta)

PostMeta object of the post.

**Retusns**: *WPModel\\PostMeta*

```
$post = new WPModel\Post($post_id);

// get meta value
echo $post->meta->custom_field;

// set meta value
$post->meta->custom_field = 'hello';
```

#### -&gt;image, -&gt;image(\[$options\])

[](#-image--imageoptions)

Get WPModel\\Image object if the post is an image attachment.

- **$options** *array*
    - **$options\['size'\]** *string*
        Specify size by string (e.g. `'full'`, `'large'`, `'medium'`, `'thumbnail'`). Default value: `'full'`

**Returns**: *WPModel\\Image*

```
$post = new WPModel\Post($post_id);

$thumbnail = $post->image(array(
  'size' => 'thumbnail'
));
echo $thumbnail->url;
echo $thumbnail->path;
echo $thumbnail->width;
echo $thumbnail->height;
```

#### -&gt;images, -&gt;images()

[](#-images--images)

Get images array if the post is an image attachment.

**Returns**: *array*

```
$post = new WPModel\Post($post_id);

$images = $post->images;

// get WPModel\Image object
$images['full'];
$images['large'];
$images['medium'];
$images['thumbnail'];
```

#### -&gt;group, -&gt;group(\[$options\])

[](#-group--groupoptions)

Retrieve posts grouped by same terms.

- **$options** *array*
    - **$options\['taxonomy'\]** *string*
        Taxonomy name. Default value: `'category'`
    - **$options\['options'\]** *array*
        Custom arguments for `WP_Query` that is internally called.
    - **$options\['map'\]** *callable*
        Default value: `array('WPModel\Post', 'create')`

**Returns**: *array*

```
$post = new WPModel\Post($post_id);

$related_posts = $post->group(array(
  'taxonomy' => 'custom_taxonomy',
  'options' => array('posts_per_page' => 5),
  'map' => function($post) {
    return CustomPostClass($post);
  },
));
```

#### -&gt;neighbor($options)

[](#-neighboroptions)

Retrieve a prev/next `WP_Post` object. Returns `null` if it doesn’t exist.

- **$options** *array*
    - **$options\['post\_type'\]** *string* | *array*
        Post type. Default value: `$this->post_type`
    - **$options\['direction'\]** *string*
        Direction of neighbor: `prev` or `next`

**Returns**: *WP\_Post*

```
$post = new WPModel\Post($post_id);

$prev_post = $post->neighbor(array(
  'post_type' => ['post', 'custom_post_type'],
  'direction' => 'prev',
));
```

#### -&gt;exists, -&gt;exists()

[](#-exists--exists)

Return `true` if the post exists.

**Returns**: *boolean*

```
$post = new WPModel\Post(0);

$post->exists; // => false
```

#### -&gt;hasChild($post)

[](#-haschildpost)

Return `true` if the value is a child of the post.

- **$post** *integer | WP\_Post | WPModel\\Post*

**Returns**: *boolean*

```
$post = new WPModel\Post($post_id);

$post->hasChild($child_post);
```

#### -&gt;matchMimeType($type)

[](#-matchmimetypetype)

Return `true` if the value matches mime type of the post. For example, `'image/jpeg'`, `'image'` and `'jpeg'` match `'image/jpeg'`.

- **$type** *string*

**Retusns**: *boolean*

```
$post = new WPModel\Post($post_id);

$post->matchMimeType('image/jpeg');
```

### PostMeta

[](#postmeta)

See `->meta` of `WPModel\Post`.

### Term

[](#term)

Extended wrapper of native term object of WordPress. See return values of [`wp_get_post_terms`](http://codex.wordpress.org/Function_Reference/wp_get_post_terms).

#### new Term($term, \[$taxonomy\]), Term::create($term, \[$taxonomy\])

[](#new-termterm-taxonomy-termcreateterm-taxonomy)

- **$term** *integer | term object*
    Term id or term object.
- **$taxonomy** *string*
    Taxonomy name.

```
// create by constructor
$term = new WPModel\Term($term_id, 'custom_taxonomy');

// get from WPModel\Post
$post = new WPModel\Post($post_id);
$terms = $post->terms(array(
  'taxonomy' => 'custom_taxonomy'
));
```

#### -&gt;children, -&gt;children(\[$options\])

[](#-children--childrenoptions-1)

Get child terms of the term.

- **$options** *array*
    See `$args` of [`get_terms`](http://codex.wordpress.org/Function_Reference/get_terms).

```
$child_terms = $term->children(array(
  'orderby' => 'count',
  'hide_empty' => false
));
```

### Image

[](#image)

See `->image` of `WPModel\Post`.

### User

[](#user)

Extended wrapper of native user object of WordPress, [`WP_User`](http://codex.wordpress.org/Class_Reference/WP_User).

#### new User(\[$user\]), User::create(\[$user\])

[](#new-useruser-usercreateuser)

- **$user** *integer | WP\_User*
    User id or WP\_User object. If not specified, returns current user.

```
// current user
$user = new WPModel\User();

// specify user id
$user = new WPModel\User($user_id);

// same properties of WP_User are accessible
echo $user->user_email;
echo $user->user_login;
echo $user->first_name;
```

#### -&gt;meta, -&gt;meta()

[](#-meta--meta-1)

UserMeta object of the user.

**Returns**: *WPModel\\UserMeta*

```
$user = new WPModel\User();

// get meta value
echo $user->meta->rich_editing;

// set meta value
$user->meta->rich_editing = 'false';
```

#### -&gt;exists, -&gt;exists()

[](#-exists--exists-1)

Return `true` if the user exists.

**Returns**: *boolean*

```
$post = new WPModel\User();

$post->exists; // => true
```

### UserMeta

[](#usermeta)

See `->meta` of `WPModel\User`.

###  Health Score

43

—

FairBetter than 90% of packages

Maintenance62

Regular maintenance activity

Popularity24

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

Established project with proven stability

 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 ~715 days

Recently: every ~1051 days

Total

7

Last Release

239d ago

Major Versions

0.1.0 → 1.0.02014-02-18

### Community

Maintainers

![](https://www.gravatar.com/avatar/9d496755b253bc4bc9d08d4a0cd28f6d00ab8d86dfccf907cb4a42f1850c8fd4?d=identicon)[hanamura](/maintainers/hanamura)

---

Top Contributors

[![hanamura](https://avatars.githubusercontent.com/u/20524?v=4)](https://github.com/hanamura "hanamura (18 commits)")

---

Tags

wordpress

### Embed Badge

![Health badge](/badges/hanamura-wp-model/health.svg)

```
[![Health](https://phpackages.com/badges/hanamura-wp-model/health.svg)](https://phpackages.com/packages/hanamura-wp-model)
```

###  Alternatives

[cloudstek/php-laff

Largest Area Fit First (LAFF) 3D box packing algorithm class for PHP

8777.5k](/packages/cloudstek-php-laff)[dereuromark/cakephp-dto

A CakePHP plugin for generating immutable Data Transfer Objects with full type safety

3096.0k5](/packages/dereuromark-cakephp-dto)[georgringer/faker

Faker for TYPO3

165.2k](/packages/georgringer-faker)

PHPackages © 2026

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