Skip to content

Instantly share code, notes, and snippets.

@Soean
Created July 29, 2021 08:35
Show Gist options
  • Save Soean/7a6e0bd68590cedb572b9f0eeca5da14 to your computer and use it in GitHub Desktop.
Save Soean/7a6e0bd68590cedb572b9f0eeca5da14 to your computer and use it in GitHub Desktop.
List all pages of Multisite
<?php
add_action(
'cli_init',
function () {
\WP_CLI::add_command( 'list_pages', function () {
$sites = get_sites();
foreach ( $sites as $site ) {
switch_to_blog( $site->blog_id );
$query_args = [
'post_type' => 'page',
'posts_per_page' => '-1',
'post_status' => 'publish',
];
foreach ( get_posts( $query_args ) as $post ) {
$permalink = get_permalink( $post );
//$permalink = str_replace('wptest.', 'www.', $permalink);
//$permalink = str_replace('.localhost.parship.dev', '', $permalink);
$permalink = str_replace('.localhost', '.integ-live', $permalink);
\WP_CLI::log( $permalink );
}
}
} );
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment