WordPress.org

Ready to get started?Download WordPress

Forums

wp_insert_post() inserts 2 posts (4 posts)

  1. miniCarl
    Member
    Posted 3 years ago #

    When i run the function wp_insert_post(), it inserts two identical posts instead of one.
    By placing echo's, I have confirmed that the function is not called twice.

    Here is some of my code:

    // Insert Pages
    $about = array(
    	'post_type' => 'page',
    	'post_status' => 'publish',
    	'post_title' => 'Om webbplatsen',
    	'post_content' => 'Content
    More content
    And even mode content'
    );
    
    wp_insert_post($about);

    You can download my full theme here;
    http://www.fristil.se/skal.rar
    The wp_insert_posts() is called in functions.php at row 44.

    Thankful for any help!

  2. miniCarl
    Member
    Posted 3 years ago #

    Bump

  3. Dion Hulse
    WordPress Dev
    Posted 3 years ago #

    Chances are, it's a Ajax request or cron request which is happening at the same time.

    I'd do something like this instead:

    $opt = get_option(..)
    if ( is_admin() && !$option ) {
    update_option(..);
    //Do my long processes here
    }

    Also... Please don't release a theme like that that sets the permalink structure to something upon activation, Respect your users choices

  4. miniCarl
    Member
    Posted 3 years ago #

    This doesn't make a difference as im testing the code without conditions...

    $check = get_option('fristil_theme_activation_check');
    		if(TRUE || $check != "set" ){

    ...or i totally missunderstood you

Topic Closed

This topic has been closed to new replies.

About this Topic