Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
<!DOCTYPE html>
<html lang="en">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Import Books</title>
<table border='1' width='100%'>
// get access to WordPress wpautop() function
$wpdb = new PDO("mysql:dbname=ricardo-wp4_db;host=localhost", "root", "root",
$books = wire('pages')->get('/books/');
$sql = "
SELECT * FROM wp_pods_books
$query = $wpdb->prepare($sql);
while($row = $query->fetch(PDO::FETCH_ASSOC)) {
$book = $books->child("wpid=$row[id]"); // do we already have this book?
if(!$book->id) {
// create a new post
$book = new Page();
$book->template = 'book';
$book->parent = $books;
echo "Creating new book...\n";
$book->wpid = $row['id'];
$book->name = wire('sanitizer')->pageName($row['name'], true);
$en = $languages->get("default");
$book->title->setLanguageValue($en, $row['name']);
$book->body->setLanguageValue($en, $row['body']);
$book->introduction->setLanguageValue($en, $row['intro']);
//add more fields if needed
$pt = $languages->get("pt");
$book->title->setLanguageValue($pt, $row['name_pt']);
$book->body->setLanguageValue($pt, $markdown->convert($row['body_pt']));
$book->introduction->setLanguageValue($pt, $markdown->convert($row['intro']));
//We need to activate portuguese page so it will appear on the front-end
$book->set("status$pt", 1);
// give detailed report about this post
echo "<tr>" .
"<td>$row[id]</td>" .
"<td>$book->title</td>" .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment