posts – How can I use wp_after_insert_post with $current_screen?

Question

I’d like to call add_action( 'wp_after_insert_post' on particular screens. I’m currently checking the page like so followed by calling the wp_after_insert_post hook. It doesn’t seem to fire but does if it’s swapped with add_action( 'current_screen', 'test' ); instead.

function test() {
    global $current_screen;

    if ( isset( $current_screen->base ) ) {
        if ( $current_screen->id == 'post' ) {

            $args = array(
                'ID'          => '10',
                'post_name'   => 'Some title',
            );
                        
            // Update the post
            wp_update_post( $args );
        }
    }
}
add_action( 'wp_after_insert_post', 'test', 100 );

0
Motivated 1 month 2022-10-30T02:30:45-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse