Forums

How to do wp_insert_post only once (4 posts)

  1. cognitions
    Member
    Posted 2 years ago #

    I have the following code in my theme functions file. The idea is to insert a page with content into the database just once when the theme is first activated. The problem is that it adds the page over an dover again every time the page is refreshed.

    Could someone identify what I could add to make this obly happen once when the theme is activated.

    <?php
    $my_post = array();
    $my_post ['post_title'] = 'Page 1';
    $my_post ['post_content'] = '[Short Code 1]';
    $my_post ['post_status'] = 'publish';
    $my_post ['post_author'] = 1;
    $my_post ['post_type'] = 'page';

    wp_insert_post( $my_post );
    ?>

  2. whooami
    Member
    Posted 2 years ago #

    one sec..

  3. whooami
    Member
    Posted 2 years ago #

    I cant find a good hook for that. you might want to post that question to the wp-hackers email list.

  4. cognitions
    Member
    Posted 2 years ago #

    OK. Good idea. Thanks for your time!

Topic Closed

This topic has been closed to new replies.

About this Topic