public static function insertCategories($selectedCategories, $postID, $postTypeSlug)
    {
        if (count($selectedCategories)) {
            $categoriesIDs = [];
            $newCategoryRelation = [];
            foreach ($selectedCategories as $selectedCategory){
                $newCategoryRelation[] = [
                  'categoryID' => $selectedCategory['categoryID'],
                  'postID' => $postID,
                ];
                $categoriesIDs[] = $selectedCategory['categoryID'];
            }

            // if post is only in the archive
            // if post is in the main database
            $insertedCategories = (new CategoryRelation())->setTable($postTypeSlug.'_categories')->insert($newCategoryRelation);
            if ($insertedCategories) {
                return $categoriesIDs;
            }
        }
        return [];
    }
public static function insertCategories($selectedCategories, $postID, $postTypeSlug)
    {
        if (count($selectedCategories)) {
            $categoriesIDs = [];
            $newCategoryRelation = [];
            foreach ($selectedCategories as $selectedCategory){
                $newCategoryRelation[] = [
                  'categoryID' => $selectedCategory['categoryID'],
                  'postID' => $postID,
                ];
                $categoriesIDs[] = $selectedCategory['categoryID'];
            }

            // if post is only in the archive
            // if post is in the main database
            $insertedCategories = (new CategoryRelation())->setTable($postTypeSlug.'_categories')->insert($newCategoryRelation);
            if ($insertedCategories) {
                return $categoriesIDs;
            }
        }
        return [];
    }
public static function insertCategories ( $ selectedCategories , $ postID , $ postTypeSlug ) { if ( count ( $ selectedCategories ) ) { $ categoriesIDs = [ ] ; $ newCategoryRelation = [ ] ; foreach ( $ selectedCategories as $ selectedCategory ) { $ newCategoryRelation [ ] = [ 'categoryID' => $ selectedCategory [ 'categoryID' ] , 'postID' => $ postID , ] ; $ categoriesIDs [ ] = $ selectedCategory [ 'categoryID' ] ; } // if post is only in the archive // if post is in the main database $ insertedCategories = ( new CategoryRelation ( ) ) -> setTable ( $ postTypeSlug . '_categories' ) -> insert ( $ newCategoryRelation ) ; if ( $ insertedCategories ) { return $ categoriesIDs ; } } return [ ] ; }
Insert Post Categories.

@param array  $selectedCategories The list of selected categories
@param int    $postID             ID of the Post
@param string $postTypeSlug       The slug of post type

@return array List of inserted categories IDs
Insert Post Categories .