Your best approach here would be to use a custom WP_CLI command to handle this. Have a read here for details – https://make.wordpress.org/cli/handbook/commands-cookbook/
Your best approach here would be to use a custom WP_CLI command to handle this. Have a read here for details – https://make.wordpress.org/cli/handbook/commands-cookbook/