Support

Account

Home Forums General Issues wp_insert_post – check unique field Reply To: wp_insert_post – check unique field

  • You can run a query for the unique_id with the below:

    
    $existingPost = get_posts( array(
        'meta_key'   => 'unique_id',
        'meta_value' => '555555',
    ));
    
    if($existingPost){
        $my_post['ID'] = $existingPost->ID;
        $post_id = wp_update_post( $my_post );
    }else{
        $post_id = wp_insert_post( $my_post );
    }