On save_post need to wp_insert_post and save partent post id to child post and child post id to parent post

Here’s an updated version of your code: add_action(‘save_post’, array($this, ‘save_post_type_example_meta_boxes’)); function save_post_type_example_meta_boxes($post_id) ………. if (…) { $new_custom_post = array( ‘post_title’ => $title, ‘post_content’ => ”, ‘post_status’ => ‘publish’, ‘post_author’ => 1, ‘post_type’ => ‘custom_post_type’, ‘meta_input’ => array( ‘meta_1’ => ‘X’, ‘parent_post_id’ => $post_id, ), ); // Prevent this action from running twice. remove_action( ‘save_post’, [ … Read more

save_post() on Menu Save

As Mr. Peattie and Mr. Nowell pointed out, you should check the post type as one of the first things in your save_post function. Here’s couple of ways how to do it, add_action( ‘save_post’, ‘prefix_my_save_post_action’, 10, 3 ); function prefix_my_save_post_action( $post_id, $post, $update ) { // Check for single post type if ( ‘my_post_type’ !== … Read more

Save_post acf data not updating category of post type

You can not use is_single() conditional tag here. You can check the type of post in the function this way: add_action( ‘save_post’, ‘set_genre_on_save’, 20, 3 ); function set_genre_on_save( $post_id, $post, $update ) { if ($post->post_type != ‘hvm’) return; // … } You can also attach the function to the action hook save_post_{post_type}, which is triggered … Read more

Get Category in save_post Hook

Unfortunately, no success after a test 🙁 I put the follwing: if ( get_post_status( $post_id ) === ‘publish’ ) { $post_title = apply_filters(‘the_title’, get_post_field(‘post_title’, $post_id)); $post_content = apply_filters(‘the_content’, get_post_field(‘post_content’, $post_id)); $taxonomy = “category”; $args = array(‘orderby’ => ‘name’, ‘order’ => ‘ASC’); $cat = wp_get_post_terms( $post_id, $taxonomy, $args ); $categorie = $cat[0]->name; I get the count … Read more