export my blogs URL links? plugin?

Hello,
Is there a way to export individual blog urls into one excel spreadsheet per blog/subdomain site?

  • Vaughan
    • Support/SLS MockingJay

    Hi @pippa,

    I don't know of a plugin that can do this, However, I just made the following which might work.

    Unzip export.php to your desktop & upload it to your public_html (or the folder containing your wp-config.php)

    Then point to it in your browser. http://domain.com/export.php

    It should give you the permalink of every single post on the network for all blogs. vYou can then click edit in your browser window and click save as to save it as a csv or txt file (which you can then convert to csv).

    Depending on the size of your network though & how many posts & blogs there are, it could run into memory issues or be very slow, but we'll get to that if need be later. it's just a basic script I just modified which was for a single site, so i've made it scan the whole network instead.

    Hope this helps

  • aristath
    • Recruit

    Hello there @Pippa,

    Do i need to backup my multisite prior to trying this?

    No, you don't.
    The code that Vaughan wrote for you will simply display what you want, it will not change anything at all on your site and nothing will be written to your database.

    Cheers,
    Ari.

  • aristath
    • Recruit

    Vaughan's code above looks like this:

    <?php
    include_once "wp-load.php";
    
    $blogs = wp_get_sites();
    
    foreach($blogs as $key) {
        switch_to_blog($key['blog_id']);
    
        $posts = new WP_Query('post_type=any&posts_per_page=-1&post_status=publish');
        $posts = $posts->posts;
    
        header('Content-type:text/plain');
        foreach($posts as $post) {
            switch ($post->post_type) {
                case 'revision':
                case 'nav_menu_item':
                    break;
                case 'page':
                    $permalink = get_page_link($post->ID);
                    break;
                case 'post':
                    $permalink = get_permalink($post->ID);
                    break;
                case 'attachment':
                    $permalink = get_attachment_link($post->ID);
                    break;
                default:
                    $permalink = get_post_permalink($post->ID);
                    break;
                    header('Content-type:text/plain');
            }
    
            $csv_title = str_replace(",", " ", $post->post_title);
            echo "\n{$permalink}";
        }
    }

    You could tweak it like this:

    <?php
    include_once "wp-load.php";
    
    $blogs = wp_get_sites();
    
    foreach($blogs as $key) {
        switch_to_blog($key['blog_id']);
    
        if ( 43 != $key['blog_id'] ) return;
    
        $posts = new WP_Query('post_type=any&posts_per_page=-1&post_status=publish');
        $posts = $posts->posts;
    
        header('Content-type:text/plain');
        foreach($posts as $post) {
            switch ($post->post_type) {
                case 'revision':
                case 'nav_menu_item':
                    break;
                case 'page':
                    $permalink = get_page_link($post->ID);
                    break;
                case 'post':
                    $permalink = get_permalink($post->ID);
                    break;
                case 'attachment':
                    $permalink = get_attachment_link($post->ID);
                    break;
                default:
                    $permalink = get_post_permalink($post->ID);
                    break;
                    header('Content-type:text/plain');
            }
    
            $csv_title = str_replace(",", " ", $post->post_title);
            echo "\n{$permalink}";
        }
    }

    Basically it's exactly the same, I just added a line there:
    if ( 43 != $key['blog_id'] ) return;
    You can change the number 43 there with the blog ID of the blog you want.

    I hope that helps!

    Cheers,
    Ari.

  • Vaughan
    • Support/SLS MockingJay

    Hi @pippa,

    You don't need to find the site ID in FTP, I think you're a little confused there.

    Once you have the site ID following the instructions Aristath has just provided.

    Open the export.php script that you uploaded to your public_html.

    Then edit the file and add the Site ID to the line that Ari added to the script.

    if ( 43 != $key['blog_id'] ) return;

    So if the site ID is 12, you change the 43 in that line to 12. Then save the file.

    Hope this helps

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.