Issue with using yoast seo meta description on save_post
-
Hello,
I am working on a WordPress Multisite, and I am trying to achieve the following:
When posting a post on Blog 1, I distribute this post to Blog 2, Blog 3 etc.
This all works perfectly, EXCEPT for the YOAST metadata. When I add Yoast Metadata for example the title or the meta description, and i click ‘update’, the metadata disappears. Please check the code below. I have no clue what’s going wrong here:
function update_content($post_id){ if (get_current_blog_id() == 1 ){ //Check it's not an auto save routine if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) { return; } $post = get_post($post_id); $title = $post->post_title; // $slug = get_page_by_path($post->post_name); $name = $post->post_name; if($post->post_type == 'post' ) { $original_id = $post_id; $original_post = get_post($original_id); // USA switch_to_blog(2); // $new_post = get_page_by_title( $title, 'OBJECT', 'post' ); $new_post = get_page_by_path( $name, 'OBJECT', 'post'); $new_post_id = $new_post->ID; $my_post = array( 'ID' => $new_post_id, 'post_author' => $original_post->post_author, 'post_date' => $original_post->post_date, 'post_modified' => $original_post->post_modified, 'post_content' => $original_post->post_content, 'post_title' => $original_post->post_title, 'post_excerpt' => $original_post->post_excerpt, 'post_status' => $original_post->post_status, 'post_name' => $original_post->post_name, 'post_type' => $original_post->post_type ); remove_action( 'save_post', 'update_content', 20, 3); if($new_post_id){ wp_update_post( $my_post ); } else{ wp_insert_post( $my_post ); } add_action('save_post', 'update_content', 20, 3); switch_to_blog(1); } } } add_action('save_post', 'update_content', 20, 3);
I would really appreciate it when someone could point me towards the right direction.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Issue with using yoast seo meta description on save_post’ is closed to new replies.