Skip to content

Instantly share code, notes, and snippets.

@BhargavBhandari90
Created September 7, 2023 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BhargavBhandari90/6ccda85f8456bcf765104bffd250291c to your computer and use it in GitHub Desktop.
Save BhargavBhandari90/6ccda85f8456bcf765104bffd250291c to your computer and use it in GitHub Desktop.
Migaration script scalaton
<?php
function test_callback_migration() {
if ( ! is_admin() && isset( $_GET['migrate_data'] ) ) {
if ( current_user_can( 'administrator' ) ) {
$page = filter_input( INPUT_GET, 'pg', FILTER_SANITIZE_NUMBER_INT );
if ( empty( $page ) ) {
$page = 1;
}
$limit = 10;
// Query all the replies.
$query = new WP_Query(
array(
'post_type' => 'post',
'post_status' => 'publish',
'paged' => $page,
'posts_per_page' => $limit,
'order' => 'ASC',
)
);
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
echo $post_id = get_the_ID();
echo '<br/>';
// Your logic goes here.
}
wp_reset_postdata();
?>
<script>
window.location.href = '<?php echo site_url() . '/?migrate_data=1&pg=' . ( $page + 1 ); ?>';
</script>
<?php
} else {
echo 'You are caught!!!! ;)';
die;
}
}
}
}
add_action( 'init', 'test_callback_migration' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment