{"id":17749832,"url":"https://github.com/stscoundrel/wp-post-crud","last_synced_at":"2025-10-22T04:31:24.316Z","repository":{"id":57050738,"uuid":"219156737","full_name":"stscoundrel/wp-post-crud","owner":"stscoundrel","description":"Provides class for handling CRUD operations on WP Posts","archived":false,"fork":false,"pushed_at":"2019-11-10T15:58:30.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-20T21:43:12.038Z","etag":null,"topics":["composer-package","crud","wordpress"],"latest_commit_sha":null,"homepage":"","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/stscoundrel.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":"2019-11-02T13:20:10.000Z","updated_at":"2019-11-10T15:58:32.000Z","dependencies_parsed_at":"2022-08-24T03:40:51.724Z","dependency_job_id":null,"html_url":"https://github.com/stscoundrel/wp-post-crud","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stscoundrel%2Fwp-post-crud","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stscoundrel%2Fwp-post-crud/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stscoundrel%2Fwp-post-crud/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stscoundrel%2Fwp-post-crud/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stscoundrel","download_url":"https://codeload.github.com/stscoundrel/wp-post-crud/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237591987,"owners_count":19335232,"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":["composer-package","crud","wordpress"],"created_at":"2024-10-26T11:25:06.740Z","updated_at":"2025-10-22T04:31:24.026Z","avatar_url":"https://github.com/stscoundrel.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WP Post Crud\n\nProvides CRUD class for handling WP Post Types in Actice Recordish way. Includes classes for detault WordPress types Post/Page and is extendable to include custom post types.\n\nAim is to abstract away awkward parts of creating, handling and deleting Posts programmatically in WordPress.\n\n## Installation\n\nVia Composer:\n\n`composer require silvanus/wp-post-crud`\n\nTo use autoloading mechanism, you must include `vendor/autoload.php` file in your code.\n\n## Issues \u0026 Contributing\n\nIf you find a bug or feel something is wrong, submit an issue or a pull request. Read the instructions first.\n\n## Usage\n\nPost CRUD gives models that have create, read, update and delete methods. Main methods: `set_field()`, `get_field()`, `save()` and `delete()`\n\n#### Creating new post\n\n```php\n\u003c?php\n\n// Default post model.\nuse Silvanus\\PostCrud\\Models\\Post as Model;\n\n// Create new post instance.\n$model = new Model();\n\n// Set some values\n$model-\u003eset_field('post_title', 'Lorem ipsum dolor sit amet');\n$model-\u003eset_field('post_content', 'Dolor sit igitur.');\n\n// Persist the data in database.\n$model-\u003esave();\n```\nAll fields values should match WP Post table columns.\n\n#### Edit existing post\n\nModels will automatically load WP Post data if you instantiate them with ID.\n\n```php\n\u003c?php\n\n// Default post model.\nuse Silvanus\\PostCrud\\Models\\Post as Model;\n\n// Pass ID of post to model.\n$model = new Model(89);\n\n// Use existing data.\necho $model-\u003eget_field('post_title');\necho $model-\u003eget_field('post_content');\necho $model-\u003eget_field('post_name');\n\n// Not a fan of that slug, change it.\n$model-\u003eset_field('post_name', 'sluggity_slug');\n\n// Persist the changes.\n$model-\u003esave();\n```\n\n#### Delete post\n\n```php\n\u003c?php\n\n// Default post model.\nuse Silvanus\\PostCrud\\Models\\Post as Model;\n\n// Post IDs to be deleted.\n$post_ids = array(1995, 2011, 2019);\n\n// These posts have been particularly silly.\nforeach( $post_ids as $post_id ) {\n    $model = new Model($post_id);\n    $model-\u003edelete();\n}\n```\n\n### Custom Post Types\n\nYou can create your own classes for your own Custom Post Types. You only need to extend AbstractCrud class and provide name of post type.\n\n\n```php\n\u003c?php\n\n// AbstractCrud class for all the heavy lifting.\nuse Silvanus\\PostCrud\\AbstractCrud;\n\n/**\n * Minimal implementation for your post type.\n */\nclass Book extends AbstractCrud\n{\n\n    /**\n     * Slug of post type you have already registered elsewhere.\n     */\n    protected $post_type = 'book';\n}\n```\n\nYour class will have access to all the same methods.\n\n```php\n\u003c?php\n\n// Your Book class\nuse YourName\\YourNamespace\\Book;\n\n// Create new post book.\n$book = new Book();\n\n// Set up book data.\n$book-\u003eset_field('post_title', 'Revelation Space');\n$book-\u003eset_field('post_status', 'published');\n\n// Persist.\n$book-\u003esave();\n```\n\n## Meta fields\n\nModels can also handle metadata. Use `set_meta()` and `get_meta()` methods.\n\n```php\n\u003c?php\n\n// Our book could use some meta data.\n$book-\u003eset_meta('author', 'Alastair Reynolds');\n$book-\u003eset_meta('rating', 5);\n\n// Persist.\n$book-\u003esave();\n```\n## Shorthand methods\n\nThere are shorthand getters \u0026 setters for the most common use cases. Instead of using `set_field($key, $value)` or `get_field($value)`, you can use the following:\n\n```php\n\u003c?php\n\n// Set values using shorthands.\n$model-\u003eset_title('Lorem ipsum');\n$model-\u003eset_content('Dolor sit igitur, dolor sit amet.');\n$model-\u003eset_excerpt('Dolor sit igitur');\n\n// Access values through shorthands\necho $model-\u003eget_title();\necho $model-\u003eget_excerpt();\n\n// Persist.\n$book-\u003esave();\n```\n\nOther shorthands are: `set_status($status)`, `get_status()`, `set_slug($slug)` and `get_slug()`. \n\nUnder the hood AbstractCrud class will call `set_field()` and `get_field()` methods.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstscoundrel%2Fwp-post-crud","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstscoundrel%2Fwp-post-crud","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstscoundrel%2Fwp-post-crud/lists"}