Created
September 7, 2023 12:12
-
-
Save BhargavBhandari90/6ccda85f8456bcf765104bffd250291c to your computer and use it in GitHub Desktop.
Migaration script scalaton
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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