Title: rest_insert_post is not working
Last modified: February 1, 2022

---

# rest_insert_post is not working

 *  [cudjex](https://wordpress.org/support/users/cudjex/)
 * (@cudjex)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/rest_insert_post-is-not-working/)
 * Hey I guys, I have strange issue. I wanna use rest_insert hook but it is not 
   working.
    Here are the doc: [https://developer.wordpress.org/reference/hooks/rest_insert_this-post_type/](https://developer.wordpress.org/reference/hooks/rest_insert_this-post_type/)
 * What I tried:
 *     ```
       function action_rest_insert_post( $post, $request, $update ) {
           $params = $request->get_json_params();
           update_post_meta($post->ID, 'ib_landing_params', $params->ib_landing_params);
       }
   
       add_action("rest_insert_post", "action_rest_insert_post", 10, 1);
       ```
   
 * I tried all ways, btw I at localhost. What is the problem?
    -  This topic was modified 4 years, 3 months ago by [Yui](https://wordpress.org/support/users/fierevere/).
    -  This topic was modified 4 years, 3 months ago by [Jan Dembowski](https://wordpress.org/support/users/jdembowski/).
      Reason: Moved to Fixing WordPress, this is not a Requests and Feedback topic
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Frest_insert_post-is-not-working%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/rest_insert_post-is-not-working/#post-15317138)
 * You’ve added incorrectly for one thing:
    `add_action("rest_insert_post", "action_rest_insert_post",
   10, 3);` (last arg should be 3, not 1)
 * If you checked the error log you should have seen a warning about invalid parameter
   count.
 *  Thread Starter [cudjex](https://wordpress.org/support/users/cudjex/)
 * (@cudjex)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/rest_insert_post-is-not-working/#post-15319020)
 * Actually I have tried with 10, 3 params too. Also I tried with my custom post
   types, it didnt work again.. Interesting really. I am adding dd(), var_dump()
   etc. to callback function but there is no error again.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/rest_insert_post-is-not-working/#post-15320723)
 * Any other issues you encounter would be around `$request` properties. When I 
   replace `$params->ib_landing_params` with a simple string it gets saved, so everything
   else is working. Verify `get_json_params()` is returning what you think it should
   be. Is it really an object and not an array?
 *  Thread Starter [cudjex](https://wordpress.org/support/users/cudjex/)
 * (@cudjex)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/rest_insert_post-is-not-working/#post-15322875)
 * I think the issue is not related with $request or $params etc. Because this is
   not working too:
 *     ```
       function action_rest_insert_post( $post, $request, $update ) {
           update_post_meta($post->ID, 'ib_landing_params', 'test');
       }
   
       add_action("rest_insert_post", "action_rest_insert_post", 10, 3);
       ```
   
 * I tried all ways and gave up lol 🙂
    -  This reply was modified 4 years, 3 months ago by [cudjex](https://wordpress.org/support/users/cudjex/).
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/rest_insert_post-is-not-working/#post-15325004)
 * You give up too easy 😛 Granted, I don’t know how much effort you’ve expended.
   FWIW, that works in my testing, so something else is amiss with the hook. Maybe
   the add_action() call occurs too late or under the wrong conditions? I put your
   code in a test plugin I use, so the action was added quite early on every request
   of any sort.
 * There are also a number of other actions that fire when a post is saved. Most
   are not REST specific, but you can check for the constant `REST_REQUEST` being
   defined from a hook like “save_post”. Using a different hook may or may not help
   any.
 * Are you sure the post is saved via a REST API request and not through other means
   like Ajax? “save_post” fires for virtually any post insertion method.
 * Anyway, instead of giving up, set the problem aside for a while, then revisit
   later. A fresh look can reveal things you’re missing right now.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘rest_insert_post is not working’ is closed to new replies.

## Tags

 * [rest](https://wordpress.org/support/topic-tag/rest/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 2 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [4 years, 3 months ago](https://wordpress.org/support/topic/rest_insert_post-is-not-working/#post-15325004)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
