Skip to content

Instantly share code, notes, and snippets.

@tonypartridge
Created July 12, 2018 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonypartridge/3f8cbd76053e9f1c0798fe1b21dad118 to your computer and use it in GitHub Desktop.
Save tonypartridge/3f8cbd76053e9f1c0798fe1b21dad118 to your computer and use it in GitHub Desktop.
Simple PHP Script to parse Wordpress posts xml export to get the relative url and prepare for Joomla! com_redirects, note using J2XML with WP Import plugin to import content quickly.
<?php
// Make sure the WP File is called wpxmlfile.xml
$xmlfile = file_get_contents('wpxmlfile.xml');
$wpfile = simplexml_load_string($xmlfile)->channel;
// Set the parent menu item alias for the posts to be accessed under
// Assumed at present it is 'News with the alias news'
$newParentAlias = '/news/';
// Auto get the link
$url = $wpfile->link;
echo '<strong>Total ITEMS: </strong> ' . count($wpfile->item) . '<br />';
// Just copy and paste the below into com_redirects bulk importer. Not using ,
// as the seperator you may want to change to | for standard J! com_redirects
// But this is configurable in com_redirect global config.
foreach ($wpfile->item AS $item) {
$relativeLink = str_replace($url, '', $item->link);
$exp_link = explode('/', $relativeLink)[3];
echo $relativeLink . ',' . $newParentAlias . $exp_link . "<br/>";
}
// Debug, comment out below lines
// echo '<pre>';
// print_r($wpfile->channel);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment