Simple WP post update sample

By

Script to replace all post slug same as the post id

    define( 'WP_USE_THEMES', false );
    require_once( 'wp-load.php' );

    $args = array(
        'post_type' => 'custom_post',
        'posts_per_page' => -1
    );
    
    $the_query = new WP_Query( $args );
    
    if ( $the_query->have_posts() ) :
	    while ( $the_query->have_posts() ) : $the_query->the_post();
	    
	        $data = array(
              'ID' => get_the_ID(),
              'post_name' => get_the_ID()
             );
            wp_update_post( $data );

		    printf("<h2>%s - %s (%s)</h2>", get_the_ID(), get_the_title(), get_post_field( 'post_name', get_the_ID()));

	    endwhile;
    
    else:
        
    endif;

Reference: https://developer.wordpress.org/reference/classes/wp_query/