WordPress.org

Ready to get started?Download WordPress

Forums

wp insert post - but only once? (2 posts)

  1. andrewkro
    Member
    Posted 3 years ago #

    Hi,

    I'm developing a theme and my client wants that with theme activation the theme would set up several pages automatically. I was referred to this function:
    wp_insert_post

    And so far I got into function.php the following:

    // Create post object
      $my_post = array();
      $my_post['post_title'] = 'My post';
      $my_post['post_content'] = 'This is my post.';
      $my_post['post_status'] = 'publish';
      $my_post['post_type'] = 'page';
    
    // Insert the post into the database
      wp_insert_post( $my_post );

    The post is inserted into database successfully, but it does so every time the function.php is called. How to make it active only once, on theme activation only?

    I'd appreciate any tips.

    Andrew

  2. andrewkro
    Member
    Posted 3 years ago #

    Has anyone worked with wp_insert_post at all?

Topic Closed

This topic has been closed to new replies.

About this Topic