I am working on a Wordpress theme that hides the default WYSIWYG editor and replaces it with a custom module system which is fine and dandy, but I've come to the realisation if someone were to use the theme on a pre-existing site they wouldn't be able to access their previously entered content which is obviously bad.

So basically what I need to do is check if a pre-existing page is loaded (via a hook hopefully) and then move that content over to the newer module system which stores data in custom fields. Is there an easy way of detecting if the post editing screen is being loaded for an already created page?

I can't rely on the post_status of "published" because I need to account for drafts and scheduled pages as well. Perhaps simply checking if a page has a title is enough to distinguish a new page from an already created page?

The below fictional code describes that I want to be able to do:

if [on page editing screen and page is pre-existing and has content]


Import the default the_editor content into a custom field

2 Answers 2


You should really only need to run this on an existing post, since new posts will be created in the manner you specify.

add_action( 'load-post.php', 'custom_content_conversion' );
function custom_content_conversion()
    if (! empty($_GET['post']) )
        // Get the post object
        $post = get_post($_GET['post']);

        // If the post object has content, store it in the meta field you are using
        if (! empty($post->post_content) )
            update_post_meta($post->ID, 'your_custom_key', $post->post_content);
  • 1
    Perfect Jake. This did the trick, thank you very much. I wasn't aware of the load-post.php hook. Apr 5, 2013 at 9:08

Just check for $_GET['post']. New posts don't have a post ID:

add_action( 'load-post-new.php', 'wpse_94212_detect_existing_post' );
add_action( 'load-post.php', 'wpse_94212_detect_existing_post' );

function wpse_94212_detect_existing_post()
    print '<pre>$post = ' . htmlspecialchars( print_r( $_GET['post'], TRUE ), ENT_QUOTES, 'utf-8', FALSE ) . "</pre>\n";

If there is an ID use get_post( $_GET['post'] ) to retrieve and change the content.

  • I appreciate you taking the time to post an answer Toscho. I awarded the answer to Jake as he provided a more complete example, but I upvoted your question. Thank you. Apr 5, 2013 at 9:07

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.