A correct hook for saving meta boxes data
A correct hook for saving meta boxes data
A correct hook for saving meta boxes data
Without knowing the surrounding code, it is hard to tell what the problem might be, but you said you checked the $post variable. Maybe the $post variable is not set properly, the save_post action only gives you the post id: function get_post_title($post_id) { $post = get_post($post_id); if (empty($post->post_title)) { // No title set, put in … Read more
Problem with ‘save_post’ hook not running
Ok, after a little playtime, here is the answer: add_action(‘save_post’, ‘ocp_jobs_save_details’); function ocp_jobs_save_details(){ global $post; $genref = sanitize_title( dechex( time() ) ); if ( $post->post_type == ‘job’ ) { if ( $_POST[‘ocp_jobs_ref’] ) { $jobs_args = array( ‘ID’ => $post->ID, ‘post_name’ => strtolower( sanitize_title( $_POST[‘ocp_jobs_ref’] ) ) ); $myref = strtoupper( $_POST[‘ocp_jobs_ref’] ); } else{ … Read more
If you are running mod_security or anything like that would be first thing to check. Security modules are server are known to react badly to WP’s POST requests. That is consistent with circumstances you describe (post saves, Ajax).
The trick is to call the hook “wp_insert_post“. But the post-type is not what you expect – post, page oder custom post type. It’s “revision”. Now you can fire a WP_Query right after the post is saved in the database.
Not entirely sure, but looks like WordPress doesn’t have a method to update custom fields in batches, so, 1 query to the DB per field.
Are you sure it isn’t saving the values to the DB? Perhaps it’s just not displaying the previously saved values in your form? $values = get_post_custom( $post->ID ); This is what you are using to get your meta – but this returns a multi-dimensional array. Therefore when accessing your beef_meta_box_price value, you need to use … Read more
How is $_GET[‘post’] set ? And why are you checking it? It could be that you’re adding the save_post call too late. Try: function foo() { die(‘Saving post’); } function foo2() { if( isset($_GET[‘post’]) ) foo(); } add_action( ‘save_post’, ‘foo2’ );
No need for the two functions/hooks – just use the first, with the addition of: if ( $post_id = wp_insert_post( $user_page ) ) { wp_update_post( array( ‘ID’ => $post_id, ‘post_name’ => $post_id, ) ); }