Created
August 9, 2021 10:31
-
-
Save janboddez/4b9cfcd9d3d6038b024c84557e1705cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Quick and dirty way to import a Twitter export into WordPress | |
*/ | |
define('WP_USE_THEMES', false); | |
require './wordpress/wp-load.php'; | |
$username = '<your-username>'; | |
$tweets = file_get_contents('tweet.js'); | |
$tweets = json_decode($tweets, true); | |
foreach ($tweets as $tweet) { | |
$datetime = DateTime::createFromFormat('D M d H:i:s P Y', $tweet['tweet']['created_at']); | |
$datetime = $datetime->format('Y-m-d H:i:s'); | |
$post_id = wp_insert_post([ | |
'post_status' => 'draft', | |
'post_type' => 'iwcpt_note', | |
'post_date_gmt' => $datetime, | |
'post_date' => get_date_from_gmt($datetime), | |
'post_title' => '', | |
'post_content' => $tweet['tweet']['full_text'], | |
'meta_input' => [ | |
'_share_on_twitter_id' => $tweet['tweet']['id_str'], | |
'_share_on_twitter_url' => 'https://twitter.com/'.$username.'/status/'.$tweet['tweet']['id_str'], | |
], | |
]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Should probably have added a check for
in_reply_to_status_id_str
and import these last and link them, if applicable, to previously imported Tweets, using a meta search and theu-in-reply-to
microformat.