{"id":22970591,"url":"https://github.com/hanamura/wp-model","last_synced_at":"2025-08-13T11:33:43.806Z","repository":{"id":12104479,"uuid":"14693465","full_name":"hanamura/wp-model","owner":"hanamura","description":"Missing functionalities from model objects of WordPress.","archived":false,"fork":false,"pushed_at":"2014-12-10T10:04:02.000Z","size":220,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-22T00:39:16.455Z","etag":null,"topics":["wordpress"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hanamura.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-11-25T17:52:30.000Z","updated_at":"2020-02-15T08:57:43.000Z","dependencies_parsed_at":"2022-09-05T11:40:12.725Z","dependency_job_id":null,"html_url":"https://github.com/hanamura/wp-model","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hanamura%2Fwp-model","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hanamura%2Fwp-model/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hanamura%2Fwp-model/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hanamura%2Fwp-model/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hanamura","download_url":"https://codeload.github.com/hanamura/wp-model/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229759840,"owners_count":18119874,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["wordpress"],"created_at":"2024-12-14T22:14:10.841Z","updated_at":"2024-12-14T22:14:11.444Z","avatar_url":"https://github.com/hanamura.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# wp-model\n\nMissing functionalities from model objects of WordPress.\n\n## API\n\n### Post\n\nExtended wrapper of native post object of WordPress, [`WP_Post`](http://codex.wordpress.org/Class_Reference/WP_Post).\n\n#### new Post($post), Post::create($post)\n\n- **$post** *integer | WP_Post*  \n  Post id or WP_Post object.\n\n```php\n$post = new WPModel\\Post($post_id);\n\n// same properties of WP_Post are accessible\necho $post-\u003epost_date;\necho $post-\u003epost_title;\necho $post-\u003epost_mime_type;\n```\n\n#### -\u003epermalink, -\u003epermalink()\n\nGet permalink of the post.\n\n**Returns**: *string*\n\n```php\n$post = new WPModel\\Post($post_id);\n\necho $post-\u003epermalink;\n```\n\n#### -\u003echildren, -\u003echildren([$options])\n\nGet child posts of the post.\n\n- **$options** *array*\n  - **$options['id']** *integer | array*  \n    Filter by ids.\n  - **$options['post_type']** *string | array*  \n    Filter by post types.\n  - **$options['post_mime_type']** *string | array*  \n    Filter by post mime types.\n\n**Returns**: *array*\n\n```php\n$post = new WPModel\\Post($post_id);\n\n$children = $post-\u003echildren(array(\n  'id' =\u003e array(10, 11, 12)\n));\n$attachments = $post-\u003echildren(array(\n  'post_type' =\u003e 'attachment'\n));\n$images = $post-\u003echildren(array(\n  'post_mime_type' =\u003e 'image'\n));\n```\n\n#### -\u003eterms, -\u003eterms([$options])\n\nGet terms attached to the post.\n\n- **$options** *array*\n  - **$options['taxonomy']** *string*  \n    Specify taxonomy. Default value: `'category'`\n\n**Returns**: *array*\n\n```php\n$post = new WPModel\\Post($post_id);\n\n$custom_terms = $post-\u003eterms(array(\n  'taxonomy' =\u003e 'custom_taxonomy'\n));\n```\n\n#### -\u003emeta, -\u003emeta()\n\nPostMeta object of the post.\n\n**Retusns**: *WPModel\\PostMeta*\n\n```php\n$post = new WPModel\\Post($post_id);\n\n// get meta value\necho $post-\u003emeta-\u003ecustom_field;\n\n// set meta value\n$post-\u003emeta-\u003ecustom_field = 'hello';\n```\n\n#### -\u003eimage, -\u003eimage([$options])\n\nGet WPModel\\Image object if the post is an image attachment.\n\n- **$options** *array*\n  - **$options['size']** *string*  \n    Specify size by string (e.g. `'full'`, `'large'`, `'medium'`, `'thumbnail'`). Default value: `'full'`\n\n**Returns**: *WPModel\\Image*\n\n```php\n$post = new WPModel\\Post($post_id);\n\n$thumbnail = $post-\u003eimage(array(\n  'size' =\u003e 'thumbnail'\n));\necho $thumbnail-\u003eurl;\necho $thumbnail-\u003epath;\necho $thumbnail-\u003ewidth;\necho $thumbnail-\u003eheight;\n```\n\n#### -\u003eimages, -\u003eimages()\n\nGet images array if the post is an image attachment.\n\n**Returns**: *array*\n\n```php\n$post = new WPModel\\Post($post_id);\n\n$images = $post-\u003eimages;\n\n// get WPModel\\Image object\n$images['full'];\n$images['large'];\n$images['medium'];\n$images['thumbnail'];\n```\n\n#### -\u003egroup, -\u003egroup([$options])\n\nRetrieve posts grouped by same terms.\n\n- **$options** *array*\n  - **$options['taxonomy']** *string*  \n    Taxonomy name. Default value: `'category'`\n  - **$options['options']** *array*  \n    Custom arguments for `WP_Query` that is internally called.\n  - **$options['map']** *callable*  \n    Default value: `array('WPModel\\Post', 'create')`\n\n**Returns**: *array*\n\n```php\n$post = new WPModel\\Post($post_id);\n\n$related_posts = $post-\u003egroup(array(\n  'taxonomy' =\u003e 'custom_taxonomy',\n  'options' =\u003e array('posts_per_page' =\u003e 5),\n  'map' =\u003e function($post) {\n    return CustomPostClass($post);\n  },\n));\n```\n\n#### -\u003eneighbor($options)\n\nRetrieve a prev/next `WP_Post` object. Returns `null` if it doesn’t exist.\n\n- **$options** *array*\n  - **$options['post_type']** *string* | *array*  \n    Post type. Default value: `$this-\u003epost_type`\n  - **$options['direction']** *string*  \n    Direction of neighbor: `prev` or `next`\n\n**Returns**: *WP_Post*\n\n```php\n$post = new WPModel\\Post($post_id);\n\n$prev_post = $post-\u003eneighbor(array(\n  'post_type' =\u003e ['post', 'custom_post_type'],\n  'direction' =\u003e 'prev',\n));\n```\n\n#### -\u003eexists, -\u003eexists()\n\nReturn `true` if the post exists.\n\n**Returns**: *boolean*\n\n```php\n$post = new WPModel\\Post(0);\n\n$post-\u003eexists; // =\u003e false\n```\n\n#### -\u003ehasChild($post)\n\nReturn `true` if the value is a child of the post.\n\n- **$post** *integer | WP_Post | WPModel\\Post*\n\n**Returns**: *boolean*\n\n```php\n$post = new WPModel\\Post($post_id);\n\n$post-\u003ehasChild($child_post);\n```\n\n#### -\u003ematchMimeType($type)\n\nReturn `true` if the value matches mime type of the post. For example, `'image/jpeg'`, `'image'` and `'jpeg'` match `'image/jpeg'`.\n\n- **$type** *string*\n\n**Retusns**: *boolean*\n\n```php\n$post = new WPModel\\Post($post_id);\n\n$post-\u003ematchMimeType('image/jpeg');\n```\n\n### PostMeta\n\nSee `-\u003emeta` of `WPModel\\Post`.\n\n### Term\n\nExtended 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).\n\n#### new Term($term, [$taxonomy]), Term::create($term, [$taxonomy])\n\n- **$term** *integer | term object*  \n  Term id or term object.\n- **$taxonomy** *string*  \n  Taxonomy name.\n\n```php\n// create by constructor\n$term = new WPModel\\Term($term_id, 'custom_taxonomy');\n\n// get from WPModel\\Post\n$post = new WPModel\\Post($post_id);\n$terms = $post-\u003eterms(array(\n  'taxonomy' =\u003e 'custom_taxonomy'\n));\n```\n\n#### -\u003echildren, -\u003echildren([$options])\n\nGet child terms of the term.\n\n- **$options** *array*  \n  See `$args` of [`get_terms`](http://codex.wordpress.org/Function_Reference/get_terms).\n\n```php\n$child_terms = $term-\u003echildren(array(\n  'orderby' =\u003e 'count',\n  'hide_empty' =\u003e false\n));\n```\n\n### Image\n\nSee `-\u003eimage` of `WPModel\\Post`.\n\n### User\n\nExtended wrapper of native user object of WordPress, [`WP_User`](http://codex.wordpress.org/Class_Reference/WP_User).\n\n#### new User([$user]), User::create([$user])\n\n- **$user** *integer | WP_User*  \n  User id or WP_User object. If not specified, returns current user.\n\n```php\n// current user\n$user = new WPModel\\User();\n\n// specify user id\n$user = new WPModel\\User($user_id);\n\n// same properties of WP_User are accessible\necho $user-\u003euser_email;\necho $user-\u003euser_login;\necho $user-\u003efirst_name;\n```\n\n#### -\u003emeta, -\u003emeta()\n\nUserMeta object of the user.\n\n**Returns**: *WPModel\\UserMeta*\n\n```php\n$user = new WPModel\\User();\n\n// get meta value\necho $user-\u003emeta-\u003erich_editing;\n\n// set meta value\n$user-\u003emeta-\u003erich_editing = 'false';\n```\n\n#### -\u003eexists, -\u003eexists()\n\nReturn `true` if the user exists.\n\n**Returns**: *boolean*\n\n```php\n$post = new WPModel\\User();\n\n$post-\u003eexists; // =\u003e true\n```\n\n### UserMeta\n\nSee `-\u003emeta` of `WPModel\\User`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhanamura%2Fwp-model","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhanamura%2Fwp-model","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhanamura%2Fwp-model/lists"}