0

I am redesigning a cms-less, flat file php website and developing it in WordPress.

The existing website is not using a database. One directory in the php site has over 100 pages and the content needs to be imported into WP.

I've created a custom content type for this directory, but does anyone have best practices or tips or plugins to migrate/import such a massive folder?

1 Answer 1

0

I assume that each php file contains the content of a page. It depends a lot on how your content is written in that php page, you should make another php script, go trough all files in that directory.

<?php

if ($handle = opendir('/path/to/files')) {
    echo "Directory handle: $handle\n";
    echo "Entries:\n";

    /* This is the correct way to loop over the directory. */
    while (false !== ($entry = readdir($handle))) {
        echo "$entry\n";
    }

    /* This is the WRONG way to loop over the directory. */
    while ($entry = readdir($handle)) {
        echo "$entry\n";
    }

    closedir($handle);
}
?>

Then get the content of each file and find some patterns where your content should be. Get the content with preg_replace and you can add the post with the content.

// Create post object
$my_post = array(
  'post_title'    => 'My post',
  'post_content'  => 'This is my post.',
  'post_status'   => 'publish',
  'post_author'   => 1,
  'post_category' => array(8,39)
);

// Insert the post into the database
wp_insert_post( $my_post );

Make sure you include or require wp_load.php on this script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.