WordPress REST API (Version 2) icon
Developer Tools

WordPress REST API (Version 2) hooks reference

  • By Ryan McCue
  • v2.0-beta15
  • Updated

WordPress REST API (Version 2) 2.0-beta15 has 11 actions and 32 filters, read directly from its source code on Nov 17, 2026. The list updates automatically when a new version is released.

How to use these hooks

Actions let you run your own code at a specific moment. Filters let you change a value before the plugin uses it. Put your code in a child theme's functions.php or a code-snippets plugin, never in the plugin's own files, because updates overwrite them.

functions.phpyour child theme
// Run your own code when WordPress REST API (Version 2) fires an action
add_action( 'rest_insert_attachment', function( $attachment, $request, $arg3 ) {
	// Your code runs here.
}, 10, 3 );

// Change a value WordPress REST API (Version 2) is about to use
add_filter( 'get_the_excerpt', function( $post_excerpt, $post ) {
	// Change $post_excerpt here.
	return $post_excerpt;
}, 10, 2 );

Parts of a name in {braces} are filled in at runtime (for example a post type or field ID). Choose Example on any hook for a ready-to-edit snippet.

All hooks

  • lib/endpoints/class-wp-rest-posts-controller.php line 1227 · used in 2 places
    /**
     * This filter is documented in wp-includes/post-template.php
     */
    apply_filters( 'get_the_excerpt', $post->post_excerpt, $post );
  • get_the_guid

    filter
    lib/endpoints/class-wp-rest-posts-controller.php line 1167 · used in 2 places
    /**
     * This filter is documented in wp-includes/post-template.php
     */
    apply_filters( 'get_the_guid', $post->guid );
  • lib/endpoints/class-wp-rest-posts-controller.php line 450 · used in 2 places
    /**
     * Fires after a single post is created or updated via the REST API.
     */
    do_action( "rest_insert_{$this->post_type}", $post, $request, true );
  • lib/endpoints/class-wp-rest-terms-controller.php line 374 · used in 2 places
    /**
     * Fires after a single term is created or updated via the REST API.
     */
    do_action( "rest_insert_{$this->taxonomy}", $term, $request, true );
  • lib/endpoints/class-wp-rest-attachments-controller.php line 154 · used in 2 places
    /**
     * Fires after a single attachment is created or updated via the REST API.
     */
    do_action( 'rest_insert_attachment', $attachment, $request, true );
  • lib/endpoints/class-wp-rest-comments-controller.php line 407 · used in 2 places
    /**
     * Fires after a comment is created or updated via the REST API.
     */
    do_action( 'rest_insert_comment', $comment, $request, true );
  • lib/endpoints/class-wp-rest-users-controller.php line 353 · used in 2 places
    /**
     * Fires after a user is created or updated via the REST API.
     */
    do_action( 'rest_insert_user', $user, $request, true );
  • the_content

    filter
    lib/endpoints/class-wp-rest-posts-controller.php line 1220 · used in 2 places
    /**
     * This filter is documented in wp-includes/post-template.php
     */
    apply_filters( 'the_content', $post->post_content );
  • the_excerpt

    filter
    lib/endpoints/class-wp-rest-posts-controller.php line 1227 · used in 2 places
    /**
     * This filter is documented in wp-includes/post-template.php
     */
    apply_filters( 'the_excerpt', apply_filters( 'get_the_excerpt', $post->post_excerpt, $post ) );
  • query_vars

    filter
    lib/endpoints/class-wp-rest-posts-controller.php line 707
    /**
     * Filter the publicly allowed query vars.
     */
    apply_filters( 'query_vars', $wp->public_query_vars );
  • lib/endpoints/class-wp-rest-posts-controller.php line 170
    /**
     * Filter the query arguments for a request.
     */
    apply_filters( "rest_{$this->post_type}_query", $args, $request );
  • lib/endpoints/class-wp-rest-posts-controller.php line 611
    /**
     * Filter whether a post is trashable.
     */
    apply_filters( "rest_{$this->post_type}_trashable", $supports_trash, $post );
  • lib/endpoints/class-wp-rest-terms-controller.php line 139
    /**
     * Filter the query arguments, before passing them to `get_terms()`.
     */
    apply_filters( "rest_{$this->taxonomy}_query", $prepared_args, $request );
  • rest_api_init

    action
    core-integration.php line 79
    /**
     * Fires when preparing to serve an API request.
     */
    do_action( 'rest_api_init', $wp_rest_server );
  • extras.php line 81
    /**
     * Filter the REST avatar sizes.
     */
    apply_filters( 'rest_avatar_sizes', array( 24, 48, 96 ) );
  • lib/endpoints/class-wp-rest-comments-controller.php line 166
    /**
     * Filter arguments, before passing to WP_Comment_Query, when querying comments
     * via the REST API.
     */
    apply_filters( 'rest_comment_query', $prepared_args, $request );
  • lib/endpoints/class-wp-rest-comments-controller.php line 534
    /**
     * Filter whether a comment is trashable.
     */
    apply_filters( 'rest_comment_trashable', ( EMPTY_TRASH_DAYS > 0 ), $comment );
  • lib/endpoints/class-wp-rest-posts-controller.php line 650
    /**
     * Fires after a single post is deleted or trashed via the REST API.
     */
    do_action( "rest_delete_{$this->post_type}", $post, $response, $request );
  • lib/endpoints/class-wp-rest-terms-controller.php line 527
    /**
     * Fires after a single term is deleted via the REST API.
     */
    do_action( "rest_delete_{$this->taxonomy}", $term, $response, $request );
  • lib/endpoints/class-wp-rest-comments-controller.php line 565
    /**
     * Fires after a comment is deleted via the REST API.
     */
    do_action( 'rest_delete_comment', $comment, $response, $request );
  • lib/endpoints/class-wp-rest-revisions-controller.php line 165
    /**
     * Fires after a revision is deleted via the REST API.
     */
    do_action( 'rest_delete_revision', $result, $request );
  • lib/endpoints/class-wp-rest-users-controller.php line 518
    /**
     * Fires after a user is deleted via the REST API.
     */
    do_action( 'rest_delete_user', $user, $response, $request );
  • lib/endpoints/class-wp-rest-posts-controller.php line 932
    /**
     * Filter a post before it is inserted via the REST API.
     */
    apply_filters( "rest_pre_insert_{$this->post_type}", $prepared_post, $request );
  • lib/endpoints/class-wp-rest-terms-controller.php line 575
    /**
     * Filter term data before inserting term via the REST API.
     */
    apply_filters( "rest_pre_insert_{$this->taxonomy}", $prepared_term, $request );
  • lib/endpoints/class-wp-rest-comments-controller.php line 367
    /**
     * Filter a comment before it is inserted via the REST API.
     */
    apply_filters( 'rest_pre_insert_comment', $prepared_comment, $request );
  • lib/endpoints/class-wp-rest-users-controller.php line 702
    /**
     * Filter user data before inserting user via the REST API.
     */
    apply_filters( 'rest_pre_insert_user', $prepared_user, $request );
  • lib/endpoints/class-wp-rest-posts-controller.php line 1316
    /**
     * Filter the post data for a response.
     */
    apply_filters( "rest_prepare_{$this->post_type}", $response, $post, $request );
  • lib/endpoints/class-wp-rest-terms-controller.php line 634
    /**
     * Filter a term item returned from the API.
     */
    apply_filters( "rest_prepare_{$this->taxonomy}", $response, $item, $request );
  • lib/endpoints/class-wp-rest-attachments-controller.php line 296
    /**
     * Filter an attachment returned from the API.
     */
    apply_filters( 'rest_prepare_attachment', $response, $post, $request );
  • lib/endpoints/class-wp-rest-comments-controller.php line 628
    /**
     * Filter a comment returned from the API.
     */
    apply_filters( 'rest_prepare_comment', $response, $comment, $request );
  • lib/endpoints/class-wp-rest-post-types-controller.php line 136
    /**
     * Filter a post type returned from the API.
     */
    apply_filters( 'rest_prepare_post_type', $response, $post_type, $request );
  • lib/endpoints/class-wp-rest-revisions-controller.php line 268
    /**
     * Filter a revision returned from the API.
     */
    apply_filters( 'rest_prepare_revision', $response, $post, $request );
  • lib/endpoints/class-wp-rest-post-statuses-controller.php line 172
    /**
     * Filter a status returned from the API.
     */
    apply_filters( 'rest_prepare_status', $response, $status, $request );
  • lib/endpoints/class-wp-rest-taxonomies-controller.php line 168
    /**
     * Filter a taxonomy returned from the API.
     */
    apply_filters( 'rest_prepare_taxonomy', $response, $taxonomy, $request );
  • lib/endpoints/class-wp-rest-users-controller.php line 620
    /**
     * Filter user data returned from the REST API.
     */
    apply_filters( 'rest_prepare_user', $response, $user, $request );
  • lib/endpoints/class-wp-rest-posts-controller.php line 724
    /**
     * Filter the allowed 'private' query vars for authorized users.
     */
    apply_filters( 'rest_private_query_vars', $wp->private_query_vars );
  • lib/endpoints/class-wp-rest-posts-controller.php line 677
    /**
     * Filter the query_vars used in `get_items` for the constructed query.
     */
    apply_filters( "rest_query_var-{$var}", $prepared_args[ $var ] );
  • lib/endpoints/class-wp-rest-posts-controller.php line 757
    /**
     * Filter allowed query vars for the REST API.
     */
    apply_filters( 'rest_query_vars', $valid_vars );
  • rest_the_post

    filter
    lib/endpoints/class-wp-rest-controller.php line 513
    /**
     * Filter the post.
     */
    apply_filters( 'rest_the_post', $post_obj, $post );
  • lib/endpoints/class-wp-rest-users-controller.php line 150
    /**
     * Filter arguments, before passing to WP_User_Query, when querying users via
     * the REST API.
     */
    apply_filters( 'rest_user_query', $prepared_args, $request );
  • core-integration.php line 66
    /**
     * Filter the REST Server Class.
     */
    apply_filters( 'wp_rest_server_class', 'WP_REST_Server' );
  • comment_text

    filter
    lib/endpoints/class-wp-rest-comments-controller.php line 591
    apply_filters( 'comment_text', $comment->comment_content, $comment );
  • lib/endpoints/class-wp-rest-comments-controller.php line 812
    apply_filters( 'rest_preprocess_comment', $prepared_comment, $request );

Generated from WordPress REST API (Version 2)'s GPL-licensed source code. Hooks inside bundled third-party libraries are not listed.

Can't find the right hook?

We can build the customisation for you. Describe what you need: