{"id":5752,"date":"2026-02-12T20:45:19","date_gmt":"2026-02-13T01:45:19","guid":{"rendered":"https:\/\/chubes.net\/?documentation=wp_rest_posts_controller"},"modified":"2026-03-13T03:29:07","modified_gmt":"2026-03-13T07:29:07","slug":"wp_rest_posts_controller","status":"publish","type":"documentation","link":"https:\/\/chubes.net\/docs\/wordpress-core\/rest-api-controllers\/wp_rest_posts_controller\/","title":{"rendered":"WP_REST_Posts_Controller"},"content":{"rendered":"<p>Core class to access posts via the REST API. The most comprehensive controller, serving as the basis for many other content-type controllers.<\/p><h2 class=\"wp-block-heading\">Class Synopsis<\/h2><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">class WP_REST_Posts_Controller extends WP_REST_Controller {\n    protected $post_type;\n    protected $meta;\n    protected $password_check_passed = array();\n    protected $allow_batch = array( &#039;v1&#039; =&gt; true );\n    \n    public function __construct( string $post_type );\n    public function register_routes();\n    \n    \/\/ Permission Checks\n    public function get_items_permissions_check( $request );\n    public function get_item_permissions_check( $request );\n    public function create_item_permissions_check( $request );\n    public function update_item_permissions_check( $request );\n    public function delete_item_permissions_check( $request );\n    \n    \/\/ CRUD Operations\n    public function get_items( $request );\n    public function get_item( $request );\n    public function create_item( $request );\n    public function update_item( $request );\n    public function delete_item( $request );\n    \n    \/\/ Data Preparation\n    protected function prepare_item_for_database( $request );\n    public function prepare_item_for_response( $item, $request );\n    protected function prepare_items_query( $prepared_args, $request );\n    \n    \/\/ Schema &amp; Parameters\n    public function get_item_schema();\n    public function get_collection_params();\n    \n    \/\/ Permission Helpers\n    public function check_read_permission( $post );\n    protected function check_update_permission( $post );\n    protected function check_create_permission( $post );\n    protected function check_delete_permission( $post );\n    protected function check_assign_terms_permission( $request );\n    \n    \/\/ Content Handling\n    public function can_access_password_content( $post, $request );\n    public function check_password_required( $required, $post );\n    protected function handle_status_param( $post_status, $post_type );\n    protected function handle_featured_media( $featured_media, $post_id );\n    protected function handle_terms( $post_id, $request );\n    protected function handle_template( $template, $post_id, $validate = false );\n    \n    \/\/ Utilities\n    protected function get_post( $id );\n    protected function prepare_date_response( $date_gmt, $date = null );\n    protected function prepare_links( $post );\n    protected function get_available_actions( $post, $request );\n    public function check_template( $template, $request );\n    public function check_status( $status, $request, $param );\n    public function sanitize_post_statuses( $statuses, $request, $parameter );\n}<\/code><\/pre><\/div><h2 class=\"wp-block-heading\">Endpoints<\/h2><figure class=\"wp-block-table\"><table><thead><tr><th>Method<\/th><th>Endpoint<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>GET<\/td><td><code>\/wp\/v2\/posts<\/code><\/td><td>List posts<\/td><\/tr><tr><td>POST<\/td><td><code>\/wp\/v2\/posts<\/code><\/td><td>Create a post<\/td><\/tr><tr><td>GET<\/td><td><code>\/wp\/v2\/posts\/{id}<\/code><\/td><td>Get a single post<\/td><\/tr><tr><td>POST\/PUT\/PATCH<\/td><td><code>\/wp\/v2\/posts\/{id}<\/code><\/td><td>Update a post<\/td><\/tr><tr><td>DELETE<\/td><td><code>\/wp\/v2\/posts\/{id}<\/code><\/td><td>Delete a post<\/td><\/tr><\/tbody><\/table><\/figure><h2 class=\"wp-block-heading\">Constructor<\/h2><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">public function __construct( string $post_type )<\/code><\/pre><\/div><p><strong>Parameters:<\/strong><\/p><ul class=\"wp-block-list\"><li><code>$post_type<\/code> &#8211; The post type slug<\/li><\/ul><p><strong>Behavior:<\/strong><\/p><ul class=\"wp-block-list\"><li>Sets <code>$this-&gt;post_type<\/code> to the provided type<\/li><li>Gets the post type object for rest_base and rest_namespace<\/li><li>Creates <code>WP_REST_Post_Meta_Fields<\/code> instance for meta handling<\/li><\/ul><h2 class=\"wp-block-heading\">Collection Parameters<\/h2><figure class=\"wp-block-table\"><table><thead><tr><th>Parameter<\/th><th>Type<\/th><th>Default<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>context<\/code><\/td><td>string<\/td><td>&#8216;view&#8217;<\/td><td>Scope under which request is made<\/td><\/tr><tr><td><code>page<\/code><\/td><td>integer<\/td><td>1<\/td><td>Current page<\/td><\/tr><tr><td><code>per_page<\/code><\/td><td>integer<\/td><td>10<\/td><td>Items per page (max 100)<\/td><\/tr><tr><td><code>search<\/code><\/td><td>string<\/td><td>&#8211;<\/td><td>Search string<\/td><\/tr><tr><td><code>after<\/code><\/td><td>date-time<\/td><td>&#8211;<\/td><td>Posts published after date<\/td><\/tr><tr><td><code>before<\/code><\/td><td>date-time<\/td><td>&#8211;<\/td><td>Posts published before date<\/td><\/tr><tr><td><code>modified_after<\/code><\/td><td>date-time<\/td><td>&#8211;<\/td><td>Posts modified after date<\/td><\/tr><tr><td><code>modified_before<\/code><\/td><td>date-time<\/td><td>&#8211;<\/td><td>Posts modified before date<\/td><\/tr><tr><td><code>author<\/code><\/td><td>array<\/td><td>[]<\/td><td>Limit to specific authors<\/td><\/tr><tr><td><code>author_exclude<\/code><\/td><td>array<\/td><td>[]<\/td><td>Exclude specific authors<\/td><\/tr><tr><td><code>exclude<\/code><\/td><td>array<\/td><td>[]<\/td><td>Exclude specific IDs<\/td><\/tr><tr><td><code>include<\/code><\/td><td>array<\/td><td>[]<\/td><td>Include specific IDs<\/td><\/tr><tr><td><code>offset<\/code><\/td><td>integer<\/td><td>&#8211;<\/td><td>Offset for pagination<\/td><\/tr><tr><td><code>order<\/code><\/td><td>string<\/td><td>&#8216;desc&#8217;<\/td><td>Sort order (asc\/desc)<\/td><\/tr><tr><td><code>orderby<\/code><\/td><td>string<\/td><td>&#8216;date&#8217;<\/td><td>Sort field<\/td><\/tr><tr><td><code>search_columns<\/code><\/td><td>array<\/td><td>[]<\/td><td>Columns to search<\/td><\/tr><tr><td><code>slug<\/code><\/td><td>array<\/td><td>&#8211;<\/td><td>Filter by slugs<\/td><\/tr><tr><td><code>status<\/code><\/td><td>array<\/td><td>&#8216;publish&#8217;<\/td><td>Filter by status<\/td><\/tr><tr><td><code>sticky<\/code><\/td><td>boolean<\/td><td>&#8211;<\/td><td>Filter sticky posts (post type only)<\/td><\/tr><tr><td><code>categories<\/code><\/td><td>array<\/td><td>&#8211;<\/td><td>Filter by categories<\/td><\/tr><tr><td><code>categories_exclude<\/code><\/td><td>array<\/td><td>&#8211;<\/td><td>Exclude categories<\/td><\/tr><tr><td><code>tags<\/code><\/td><td>array<\/td><td>&#8211;<\/td><td>Filter by tags<\/td><\/tr><tr><td><code>tags_exclude<\/code><\/td><td>array<\/td><td>&#8211;<\/td><td>Exclude tags<\/td><\/tr><\/tbody><\/table><\/figure><h3 class=\"wp-block-heading\">Orderby Options<\/h3><ul class=\"wp-block-list\"><li><code>author<\/code> &#8211; Author ID<\/li><li><code>date<\/code> &#8211; Publish date<\/li><li><code>id<\/code> &#8211; Post ID<\/li><li><code>include<\/code> &#8211; Order by include parameter<\/li><li><code>modified<\/code> &#8211; Modified date<\/li><li><code>parent<\/code> &#8211; Parent ID<\/li><li><code>relevance<\/code> &#8211; Search relevance (requires search)<\/li><li><code>slug<\/code> &#8211; Post slug<\/li><li><code>include_slugs<\/code> &#8211; Order by slug include<\/li><li><code>title<\/code> &#8211; Post title<\/li><li><code>menu_order<\/code> &#8211; Menu order (pages\/page-attributes)<\/li><\/ul><h2 class=\"wp-block-heading\">Schema Properties<\/h2><p>The schema varies based on post type support. Core properties:<\/p><figure class=\"wp-block-table\"><table><thead><tr><th>Property<\/th><th>Type<\/th><th>Context<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>id<\/code><\/td><td>integer<\/td><td>view, edit, embed<\/td><td>Post ID (readonly)<\/td><\/tr><tr><td><code>date<\/code><\/td><td>string\/null<\/td><td>view, edit, embed<\/td><td>Publish date (site timezone)<\/td><\/tr><tr><td><code>date_gmt<\/code><\/td><td>string\/null<\/td><td>view, edit<\/td><td>Publish date (GMT)<\/td><\/tr><tr><td><code>guid<\/code><\/td><td>object<\/td><td>view, edit<\/td><td>Global unique identifier (readonly)<\/td><\/tr><tr><td><code>link<\/code><\/td><td>string<\/td><td>view, edit, embed<\/td><td>Post URL (readonly)<\/td><\/tr><tr><td><code>modified<\/code><\/td><td>string<\/td><td>view, edit<\/td><td>Modified date (readonly)<\/td><\/tr><tr><td><code>modified_gmt<\/code><\/td><td>string<\/td><td>view, edit<\/td><td>Modified date GMT (readonly)<\/td><\/tr><tr><td><code>slug<\/code><\/td><td>string<\/td><td>view, edit, embed<\/td><td>Post slug<\/td><\/tr><tr><td><code>status<\/code><\/td><td>string<\/td><td>view, edit<\/td><td>Post status<\/td><\/tr><tr><td><code>type<\/code><\/td><td>string<\/td><td>view, edit, embed<\/td><td>Post type (readonly)<\/td><\/tr><tr><td><code>password<\/code><\/td><td>string<\/td><td>edit<\/td><td>Post password<\/td><\/tr><\/tbody><\/table><\/figure><h3 class=\"wp-block-heading\">Conditional Properties (based on post_type_supports)<\/h3><figure class=\"wp-block-table\"><table><thead><tr><th>Property<\/th><th>Support<\/th><th>Type<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>title<\/code><\/td><td>&#8216;title&#8217;<\/td><td>object<\/td><td>Post title (raw\/rendered)<\/td><\/tr><tr><td><code>content<\/code><\/td><td>&#8216;editor&#8217;<\/td><td>object<\/td><td>Post content (raw\/rendered\/protected\/block_version)<\/td><\/tr><tr><td><code>author<\/code><\/td><td>&#8216;author&#8217;<\/td><td>integer<\/td><td>Author user ID<\/td><\/tr><tr><td><code>excerpt<\/code><\/td><td>&#8216;excerpt&#8217;<\/td><td>object<\/td><td>Post excerpt (raw\/rendered\/protected)<\/td><\/tr><tr><td><code>featured_media<\/code><\/td><td>&#8216;thumbnail&#8217;<\/td><td>integer<\/td><td>Featured image ID<\/td><\/tr><tr><td><code>comment_status<\/code><\/td><td>&#8216;comments&#8217;<\/td><td>string<\/td><td>Comments open\/closed<\/td><\/tr><tr><td><code>ping_status<\/code><\/td><td>&#8216;comments&#8217;<\/td><td>string<\/td><td>Pingbacks open\/closed<\/td><\/tr><tr><td><code>menu_order<\/code><\/td><td>&#8216;page-attributes&#8217;<\/td><td>integer<\/td><td>Menu order<\/td><\/tr><tr><td><code>format<\/code><\/td><td>&#8216;post-formats&#8217;<\/td><td>string<\/td><td>Post format<\/td><\/tr><tr><td><code>meta<\/code><\/td><td>&#8216;custom-fields&#8217;<\/td><td>object<\/td><td>Post meta<\/td><\/tr><tr><td><code>sticky<\/code><\/td><td>(post type only)<\/td><td>boolean<\/td><td>Is sticky<\/td><\/tr><tr><td><code>template<\/code><\/td><td>&#8211;<\/td><td>string<\/td><td>Page template<\/td><\/tr><tr><td><code>parent<\/code><\/td><td>(hierarchical)<\/td><td>integer<\/td><td>Parent post ID<\/td><\/tr><tr><td><code>categories<\/code><\/td><td>(taxonomy)<\/td><td>array<\/td><td>Category term IDs<\/td><\/tr><tr><td><code>tags<\/code><\/td><td>(taxonomy)<\/td><td>array<\/td><td>Tag term IDs<\/td><\/tr><\/tbody><\/table><\/figure><h2 class=\"wp-block-heading\">Permission Checks<\/h2><h3 class=\"wp-block-heading\">get_items_permissions_check()<\/h3><ul class=\"wp-block-list\"><li>Returns <code>true<\/code> for public requests<\/li><li>Requires <code>edit_posts<\/code> capability for <code>edit<\/code> context<\/li><\/ul><h3 class=\"wp-block-heading\">get_item_permissions_check()<\/h3><ul class=\"wp-block-list\"><li>Verifies post exists and matches controller&#8217;s post type<\/li><li>Checks password if provided<\/li><li>Requires <code>edit_post<\/code> capability for <code>edit<\/code> context<\/li><li>Calls <code>check_read_permission()<\/code> for view context<\/li><\/ul><h3 class=\"wp-block-heading\">create_item_permissions_check()<\/h3><ul class=\"wp-block-list\"><li>Requires <code>create_posts<\/code> capability<\/li><li>Checks <code>edit_others_posts<\/code> for setting different author<\/li><li>Checks <code>edit_others_posts<\/code> or <code>publish_posts<\/code> for sticky<\/li><li>Validates term assignment permissions<\/li><\/ul><h3 class=\"wp-block-heading\">update_item_permissions_check()<\/h3><ul class=\"wp-block-list\"><li>Requires <code>edit_post<\/code> capability<\/li><li>Additional checks for author, sticky, and terms<\/li><\/ul><h3 class=\"wp-block-heading\">delete_item_permissions_check()<\/h3><ul class=\"wp-block-list\"><li>Requires <code>delete_post<\/code> capability<\/li><\/ul><h2 class=\"wp-block-heading\">Key Methods<\/h2><h3 class=\"wp-block-heading\">get_post()<\/h3><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">protected function get_post( int $id ): WP_Post|WP_Error<\/code><\/pre><\/div><p>Gets the post if ID is valid and matches the controller&#8217;s post type.<\/p><h3 class=\"wp-block-heading\">check_read_permission()<\/h3><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">public function check_read_permission( WP_Post $post ): bool<\/code><\/pre><\/div><p>Checks if a post can be read. Handles:<\/p><ul class=\"wp-block-list\"><li>Published posts (always readable)<\/li><li>Private posts (requires <code>read_post<\/code> capability)<\/li><li>Inherited status (checks parent)<\/li><li>Public post statuses<\/li><\/ul><h3 class=\"wp-block-heading\">prepare_item_for_database()<\/h3><p>Maps request parameters to post object properties:<\/p><ul class=\"wp-block-list\"><li><code>title<\/code> \u2192 <code>post_title<\/code><\/li><li><code>content<\/code> \u2192 <code>post_content<\/code><\/li><li><code>excerpt<\/code> \u2192 <code>post_excerpt<\/code><\/li><li><code>status<\/code> \u2192 <code>post_status<\/code><\/li><li><code>date<\/code>\/<code>date_gmt<\/code> \u2192 <code>post_date<\/code>\/<code>post_date_gmt<\/code><\/li><li><code>slug<\/code> \u2192 <code>post_name<\/code><\/li><li><code>author<\/code> \u2192 <code>post_author<\/code><\/li><li><code>password<\/code> \u2192 <code>post_password<\/code><\/li><li><code>parent<\/code> \u2192 <code>post_parent<\/code><\/li><li><code>menu_order<\/code> \u2192 <code>menu_order<\/code><\/li><li><code>comment_status<\/code> \u2192 <code>comment_status<\/code><\/li><li><code>ping_status<\/code> \u2192 <code>ping_status<\/code><\/li><\/ul><h3 class=\"wp-block-heading\">prepare_item_for_response()<\/h3><p>Prepares full post response including:<\/p><ul class=\"wp-block-list\"><li>All schema fields based on context<\/li><li>Taxonomy terms<\/li><li>Meta fields<\/li><li>Links (self, collection, author, replies, revisions, etc.)<\/li><\/ul><h3 class=\"wp-block-heading\">handle_terms()<\/h3><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">protected function handle_terms( int $post_id, WP_REST_Request $request ): null|WP_Error<\/code><\/pre><\/div><p>Updates post terms from request data using <code>wp_set_object_terms()<\/code>.<\/p><h3 class=\"wp-block-heading\">handle_featured_media()<\/h3><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">protected function handle_featured_media( int $featured_media, int $post_id ): bool|WP_Error<\/code><\/pre><\/div><p>Sets or removes the post thumbnail.<\/p><h3 class=\"wp-block-heading\">handle_template()<\/h3><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">public function handle_template( string $template, int $post_id, bool $validate = false )<\/code><\/pre><\/div><p>Sets the page template via <code>_wp_page_template<\/code> meta.<\/p><h2 class=\"wp-block-heading\">Response Links<\/h2><p>The controller adds HAL-style links:<\/p><figure class=\"wp-block-table\"><table><thead><tr><th>Relation<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>self<\/code><\/td><td>Link to this post<\/td><\/tr><tr><td><code>collection<\/code><\/td><td>Link to posts collection<\/td><\/tr><tr><td><code>about<\/code><\/td><td>Link to post type<\/td><\/tr><tr><td><code>author<\/code><\/td><td>Link to author (embeddable)<\/td><\/tr><tr><td><code>replies<\/code><\/td><td>Link to comments (embeddable)<\/td><\/tr><tr><td><code>version-history<\/code><\/td><td>Link to revisions<\/td><\/tr><tr><td><code>predecessor-version<\/code><\/td><td>Link to latest revision<\/td><\/tr><tr><td><code>up<\/code><\/td><td>Link to parent (hierarchical)<\/td><\/tr><tr><td><code>wp:featuredmedia<\/code><\/td><td>Link to featured image (embeddable)<\/td><\/tr><tr><td><code>wp:attachment<\/code><\/td><td>Link to attachments<\/td><\/tr><tr><td><code>wp:term<\/code><\/td><td>Links to taxonomy terms (embeddable)<\/td><\/tr><\/tbody><\/table><\/figure><h2 class=\"wp-block-heading\">Action Links<\/h2><p>Edit context includes action links indicating user capabilities:<\/p><figure class=\"wp-block-table\"><table><thead><tr><th>Action<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>wp:action-publish<\/code><\/td><td>Can publish posts<\/td><\/tr><tr><td><code>wp:action-unfiltered-html<\/code><\/td><td>Can use unfiltered HTML<\/td><\/tr><tr><td><code>wp:action-sticky<\/code><\/td><td>Can make posts sticky<\/td><\/tr><tr><td><code>wp:action-assign-author<\/code><\/td><td>Can change author<\/td><\/tr><tr><td><code>wp:action-create-{taxonomy}<\/code><\/td><td>Can create terms<\/td><\/tr><tr><td><code>wp:action-assign-{taxonomy}<\/code><\/td><td>Can assign terms<\/td><\/tr><\/tbody><\/table><\/figure><h2 class=\"wp-block-heading\">Usage Example<\/h2><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ Get posts with specific parameters\n$request = new WP_REST_Request( &#039;GET&#039;, &#039;\/wp\/v2\/posts&#039; );\n$request-&gt;set_param( &#039;per_page&#039;, 5 );\n$request-&gt;set_param( &#039;categories&#039;, array( 1, 2 ) );\n$request-&gt;set_param( &#039;orderby&#039;, &#039;title&#039; );\n$request-&gt;set_param( &#039;order&#039;, &#039;asc&#039; );\n\n$controller = new WP_REST_Posts_Controller( &#039;post&#039; );\n$response = $controller-&gt;get_items( $request );\n\n\/\/ Create a post\n$request = new WP_REST_Request( &#039;POST&#039;, &#039;\/wp\/v2\/posts&#039; );\n$request-&gt;set_param( &#039;title&#039;, &#039;My New Post&#039; );\n$request-&gt;set_param( &#039;content&#039;, &#039;Post content here.&#039; );\n$request-&gt;set_param( &#039;status&#039;, &#039;publish&#039; );\n$request-&gt;set_param( &#039;categories&#039;, array( 1 ) );\n\n$response = $controller-&gt;create_item( $request );<\/code><\/pre><\/div><h2 class=\"wp-block-heading\">Extending for Custom Post Types<\/h2><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ Register custom post type with REST support\nregister_post_type( &#039;book&#039;, array(\n    &#039;public&#039;       =&gt; true,\n    &#039;show_in_rest&#039; =&gt; true,\n    &#039;rest_base&#039;    =&gt; &#039;books&#039;,\n    &#039;supports&#039;     =&gt; array( &#039;title&#039;, &#039;editor&#039;, &#039;author&#039;, &#039;thumbnail&#039;, &#039;custom-fields&#039; ),\n));\n\n\/\/ Endpoint automatically available at \/wp\/v2\/books<\/code><\/pre><\/div><h2 class=\"wp-block-heading\">Source<\/h2><p><code>wp-includes\/rest-api\/endpoints\/class-wp-rest-posts-controller.php<\/code><\/p><h2 class=\"wp-block-heading\">Since<\/h2><p>WordPress 4.7.0<\/p><h2 class=\"wp-block-heading\">Changelog<\/h2><figure class=\"wp-block-table\"><table><thead><tr><th>Version<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>4.7.0<\/td><td>Introduced<\/td><\/tr><tr><td>5.0.0<\/td><td>Added <code>rest_after_insert_{$post_type}<\/code> action<\/td><\/tr><tr><td>5.4.0<\/td><td>Added <code>tax_relation<\/code> parameter<\/td><\/tr><tr><td>5.6.0<\/td><td>Added <code>check_status()<\/code> method<\/td><\/tr><tr><td>5.7.0<\/td><td>Added <code>modified_after<\/code> and <code>modified_before<\/code> parameters<\/td><\/tr><tr><td>5.7.1<\/td><td>Added password check bypass for REST requests<\/td><\/tr><tr><td>5.9.0<\/td><td>Added batching support<\/td><\/tr><\/tbody><\/table><\/figure>","protected":false},"excerpt":{"rendered":"<p>Core class to access posts via the REST API. The most comprehensive controller, serving as the basis for many other content-type controllers. Class Synopsis class WP_REST_Posts_Controller extends WP_REST_Controller { protected&#8230;<\/p>\n","protected":false},"featured_media":0,"template":"","meta":{"footnotes":""},"tags":[],"project":[652],"project_type":[749],"class_list":["post-5752","documentation","type-documentation","status-publish","hentry","project-rest-api-controllers","project_type-wordpress-reference"],"project_info":{"id":589,"name":"WordPress Core","slug":"wordpress-core"},"project_type_info":{"id":749,"name":"WordPress Reference","slug":"wordpress-reference"},"_links":{"self":[{"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/documentation\/5752","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/documentation"}],"about":[{"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/types\/documentation"}],"version-history":[{"count":3,"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/documentation\/5752\/revisions"}],"predecessor-version":[{"id":8792,"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/documentation\/5752\/revisions\/8792"}],"wp:attachment":[{"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/media?parent=5752"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/tags?post=5752"},{"taxonomy":"project","embeddable":true,"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/project?post=5752"},{"taxonomy":"project_type","embeddable":true,"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/project_type?post=5752"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}