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)

  • What is your custom post type called? Can we see details? Where is this code placed?
    – Tom J Nowell
    Mar 16, 2015 at 1:53
  • @PieterGoosen save_post is an action hook used in ALL post types, including standard posts, pages and custom post types. Also, the post-type specific hook is save_post_{post_type}, not save_{post_type}.
    – cybmeta
    Mar 16, 2015 at 7:41
  • The code can be found at gist.github.com/mikeyhoward1977/566ce073fbdc7cf167f2/… the save_post hook is in metabox.php
    – Mike
    Mar 16, 2015 at 10:27
  • I tried save_{post_type} but still nothing. I have also tried, edit_post and publish_post
    – Mike
    Mar 16, 2015 at 10:34


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.