filters – Replace Data In Post & Update Meta Field Post Is Saved

Question

I’m a bit lost & I’m wondering if someone can help.

I have a post that is being generated from a podcast feed. That feed contains an audio player using the <audio> tag. I wanted to remove that audio player but store the MP3 file in a custom metabox, so it can be manipulated separately later on.

Here’s the code I have so far…

function post_is_created($post_id, $post, $update) {
    if ( $post->post_type == 'post' && $post->post_status == 'publish' && empty(get_post_meta($post_id, 'check_if_run_once')) ) {
        
        $old_content = $post->post_content;
        $start_tag = '';
        $end_tag = '';
        
        
        $my_data = get_string_between($old_content, $start_tag, $end_tag);
        
        $this_replace = array('<p>'.$start_tag,$end_tag.'</p>',$my_data);
        
        $new_content = str_replace($this_replace,'',$old_content);
        
        $post->post_content = $new_content;
        
        
        
        if($my_data != ''){
            update_post_meta( $post_id, '_pca_podcast_audio', $my_data );
        }
        update_post_meta( $post_id, 'check_if_run_once', true );
        
        return $post;
    }
}

add_action( 'wp_insert_post', 'post_is_created', 10, 3 );

I am performing all of the actions to save the metadata and sanitise the content in the way I want, but I’m at a loss to understand how I now update the post.

I have tried wp_insert_post_data and content_save_pre but neither seem to work… I’m clearly doing something wrong.

How can I save this data?

0
Steve Mellor 4 months 2022-04-10T19:37:51-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse