Skip to content

Instantly share code, notes, and snippets.

@leobaiano
Created August 29, 2014 14:28
Show Gist options
  • Save leobaiano/6522e0e473c2a2fb2892 to your computer and use it in GitHub Desktop.
Save leobaiano/6522e0e473c2a2fb2892 to your computer and use it in GitHub Desktop.
Migrar posts de um site WordPress para outro
<?php
ignore_user_abort(1);
set_time_limit(0);
@ini_set('max_execution_time', 0);
include(ABSPATH . "wp-blog-header.php");
$fotos = $wpdb->get_results("SELECT * FROM videos ORDER BY id DESC");
foreach( $fotos as $foto ){
$titulo = $foto->titulo;
$youtube = $foto->youtube;
$imagem = $foto->imagem;
// Insert post
$defaults = array(
'post_status' => 'publish',
'post_type' => 'videos',
'post_author' => 1,
'post_title' => $titulo,
'post_content' => $conteudo,
);
$post_id = wp_insert_post( $defaults );
update_post_meta($post_id, 'url_do_video_no_youtube', $youtube);
$caminho_int = "wp-content/uploads/2014/04/" . urldecode( basename( $imagem ) );
copy( $imagem, $caminho_int );
$wp_filetype = wp_check_filetype( basename($caminho_int), null );
$wp_upload_dir = wp_upload_dir();
$attachment = array(
'guid' => $wp_upload_dir['url'] . '/' . basename( $caminho_int ),
'post_mime_type' => $wp_filetype['type'],
'post_title' => preg_replace('/\.[^.]+$/', '', basename( $caminho_int ) ),
'post_content' => '',
'post_status' => 'inherit'
);
$attach_id = wp_insert_attachment( $attachment, $caminho_int, $post_id );
require_once( ABSPATH . 'wp-admin/includes/image.php' );
$attach_data = wp_generate_attachment_metadata( $attach_id, $caminho_int );
wp_update_attachment_metadata( $attach_id, $attach_data );
set_post_thumbnail( $post_id, $attach_id );
echo $titulo . '<br />';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment