Make WordPress Core

Ticket #17379: export_attachments_for_cpt.diff

File export_attachments_for_cpt.diff, 1.3 KB (added by jghazally, 12 years ago)

Include attachments for specific post_types

  • wp-admin/includes/export.php

     
    3232
    3333        do_action( 'export_wp' );
    3434
     35        $get_attachments = false;
     36
    3537        $sitename = sanitize_key( get_bloginfo( 'name' ) );
    3638        if ( ! empty($sitename) ) $sitename .= '.';
    3739        $filename = $sitename . 'wordpress.' . date( 'Y-m-d' ) . '.xml';
     
    4648                        $args['content'] = 'post';
    4749
    4850                $where = $wpdb->prepare( "{$wpdb->posts}.post_type = %s", $args['content'] );
     51                $get_attachments = true;
    4952        } else {
    5053                $post_types = get_post_types( array( 'can_export' => true ) );
    5154                $esses = array_fill( 0, count($post_types), '%s' );
     
    7982        // grab a snapshot of post IDs, just in case it changes during the export
    8083        $post_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} $join WHERE $where" );
    8184
     85        if ( $get_attachments ) {
     86                $attachment_ids = $wpdb->get_col( "SELECT ID
     87                        FROM {$wpdb->posts}
     88                        WHERE {$wpdb->posts}.post_type ='attachment'
     89                        AND {$wpdb->posts}.post_parent IN (".implode(',', $post_ids).")" );
     90                $post_ids = array_merge($post_ids, $attachment_ids);
     91        }
     92
    8293        // get the requested terms ready, empty unless posts filtered by category or all content
    8394        $cats = $tags = $terms = array();
    8495        if ( isset( $term ) && $term ) {