Skip to:
Content
Pages
Categories
Search
Top
Bottom

wp_insert_post posting duplicates in function


  • ekko848
    Participant

    @ekko848

    Here is my code

    function buddydev_create_post_on_activation( $user_id, $key, $user ) {
       
        if ( get_page_by_title( $bandname, null, 'artists' ) == FALSE ){
            $new_post1 = array(
        'post_title' => $bandname,
        'post_content' => $postcontent,
        'post_status' => 'publish',
        'post_type' => 'artists',
        'post_category' => array(0)
    );
    
    $post_ID = wp_insert_post($new_post1);
    wp_insert_post( $new_post1 );
    
    		  }
    
    add_action( 'bp_core_activated_user', 'buddydev_create_post_on_activation', 10, 3 );

    I’ve just recently added if ( get_page_by_title( $bandname, null, 'artists' ) == FALSE ), or I also tried if (!get_page_by_title( $bandname, null, 'artists' )), but this does not seem to help.

    It is posting two duplicate posts with title of $bandname value.

    Anyone have any idea on what could be causing this and how to fix it?

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar