Title: Problem with &#039;save_post&#039; hook not running
Last modified: August 22, 2016

---

# Problem with 'save_post' hook not running

 *  Resolved [Michael](https://wordpress.org/support/users/mikeyhoward1977/)
 * (@mikeyhoward1977)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/problem-with-save_post-hook-not-running/)
 * I have a custom post type, with a custom meta box which contains a number of 
   input fields.
 * The meta box is displaying fine but when completing all the fields the data is
   not saving, in fact, the function I call with the `save_post`hook does not appear
   to be running at all…
 * I use the `register_meta_box_cb` to define my function which adds the meta box
   for me. I then use the following in my attempt to save the custom data…
 *     ```
       add_action( 'save_post', 'my_save_function', 10, 2 );
       function my_save_function( $post_id, $post )	{
       foreach( $_POST as $meta_key => $new_meta_value )	{
       if( substr( $meta_key, 0, 6 ) == 'venue_' )	{ // This is verified and correct
       update_post_meta( $post_id, $meta_key, $new_meta_value );
       }
       }
       }
       ```
   
 * Been staring at this and searching the codex and Google for a couple of hours
   now with no progress… Whatever I put in that save function just does not execute.
   I have tried die() and error_log at the very top of the function to ensure my
   checks are not the problem… but nothing. (the function above is a cut down version
   to what I really have)

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

 *  [vidhumohan](https://wordpress.org/support/users/vidhumohan/)
 * (@vidhumohan)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/problem-with-save_post-hook-not-running/#post-5902286)
 * Hi,
    Try the function with action hooks publish_post and edit_post.
 *  Thread Starter [Michael](https://wordpress.org/support/users/mikeyhoward1977/)
 * (@mikeyhoward1977)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/problem-with-save_post-hook-not-running/#post-5902288)
 * Thanks for the response. Unfortunately I get the same result with both those 
   hooks too – the function is not running. I added `error_log( 'Got gere' );` to
   the top of the function but nothing.
 * Full debugging is enabled also and nothing in the debug file.
 *  Thread Starter [Michael](https://wordpress.org/support/users/mikeyhoward1977/)
 * (@mikeyhoward1977)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/problem-with-save_post-hook-not-running/#post-5902298)
 * The Gist for the code can be found [here](https://gist.github.com/mikeyhoward1977/566ce073fbdc7cf167f2).
 * the save_post action and associated function are in the metabox.php file
 *  [vidhumohan](https://wordpress.org/support/users/vidhumohan/)
 * (@vidhumohan)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/problem-with-save_post-hook-not-running/#post-5902304)
 * Did you tried the plugin advanced custom field, [https://wordpress.org/plugins/advanced-custom-fields/](https://wordpress.org/plugins/advanced-custom-fields/)
 *  Thread Starter [Michael](https://wordpress.org/support/users/mikeyhoward1977/)
 * (@mikeyhoward1977)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/problem-with-save_post-hook-not-running/#post-5902306)
 * A plugin does not meet my needs… This is for my own plugin. I can’t have a dependency
   on another plugin
 *  Thread Starter [Michael](https://wordpress.org/support/users/mikeyhoward1977/)
 * (@mikeyhoward1977)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/problem-with-save_post-hook-not-running/#post-5902308)
 * OK seems I needed the `save_post` hook to be in the main class rather than called
   elsewhere.
 * I added `add_action( 'save_post', array( $this, 'save_custom_post' ), 10, 2 );`
   to the __construct function in my main class and now it works

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

The topic ‘Problem with 'save_post' hook not running’ is closed to new replies.

## Tags

 * [custom post](https://wordpress.org/support/topic-tag/custom-post/)
 * [save_post](https://wordpress.org/support/topic-tag/save_post/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 6 replies
 * 2 participants
 * Last reply from: [Michael](https://wordpress.org/support/users/mikeyhoward1977/)
 * Last activity: [11 years, 2 months ago](https://wordpress.org/support/topic/problem-with-save_post-hook-not-running/#post-5902308)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
