Add meta field after post has been published

You can hook into post_updated action, if you want to access the post’s data after it’s been published. This hook passes the post’s ID, inundated post object, and updated post object. add_action( ‘post_updated’, ‘update_event_date’, 10, 3 ); function update_event_date( $post_id, $post_after, $post_before ){ $post_type = get_post_type( $post_id ); $event_datee = get_post_meta( $post_id, ‘_EventStartDate’, true ); … Read more

Write automatic title at save_post (infinite loop)

There is a simple way, You need to use filter hook wp_insert_post_data So the code should be like add_filter( ‘wp_insert_post_data’, ‘set_post_title_with_field_value’ ); function set_post_title_with_field_value( $data ) { if ($data[‘post_type’] == ‘sentence’ ){ $sentence_number = get_field(‘sentencia_no’, $data[‘ID’]); $data[‘post_title’] = $sentence_number; } return $data; } You need to add this code into theme’s functions.php. So try the … Read more

Confusion regarding Nonce & using it in Custom Columns for Saving Checkbox Value to Post Meta

When trying to create a custom metabox, adding custom columns, managing custom columns and finally saving the post. Where do we need to pass the nonce. To make my question clearer. This is not correct, you shouldn’t need a nonce in a metabox because all that information is sent at once in the full request … Read more

Execute function after a post has been published

function check_meta( $post_id, $post, $update ) { $post_type = get_post_type($post_id); if ( “post” != $post_type ) return; $video_code_val = get_post_meta( $post_id, ‘video_code’, true ); // Check if the video_code field has a value. if ( ! empty( $video_code_val ) ){ //if it does, set post format set_post_format( $post_id, ‘video’ ); } } add_action( ‘save_post’, ‘check_meta’, … Read more

Metabox saves on Update or Publish, but not on Saving Draft

So you first tried hooking on to wp_insert_post_data and could save the meta data when saving Drafts but not when publishing. Then you tried hooking on to save_post and could save meta data when publishing but not when saving Drafts. The easiest solution would be to hook on to both. add_action(‘save_post’, ‘save_details’); add_action(‘wp_insert_post_data’, ‘save_details’); Edit … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)