### Run WordPress to Craft CMS Import (CLI) Source: https://context7.com/craftcms/wp-import/llms.txt Execute the WordPress to Craft CMS import process using the command line. Supports interactive prompts for URL and credentials, or non-interactive setup with provided details. ```bash # Interactive import with prompts for WordPress URL and credentials ddev craft wp-import # Non-interactive with credentials ddev craft wp-import \ --apiUrl="https://example.com" \ --username="admin" \ --password="xxxx xxxx xxxx xxxx xxxx xxxx" ``` -------------------------------- ### Basic Importer Structure for Products in PHP Source: https://context7.com/craftcms/wp-import/llms.txt Defines the basic structure for importing WordPress 'product' post types into Craft CMS. It specifies the API endpoint, element type, query parameters, and how to populate Craft entry fields from WordPress data. It also includes logic for finding existing entries and preparing the Craft environment before import. ```php // config/wp-import/importers/Product.php namespace config\wpimport\importers; use Craft; use craft\base\ElementInterface; use craft\elements\Entry; use craft\wpimport\BaseImporter; class Product extends BaseImporter { public function slug(): string { return 'product'; // WordPress post type slug } public function apiUri(): string { return 'wp/v2/product'; // WordPress REST API endpoint } public function label(): string { return 'Products'; // Display name } public function elementType(): string { return Entry::class; // Craft element type } public function queryParams(): array { return [ 'status' => 'publish,draft', 'orderby' => 'date', 'order' => 'desc', ]; } public function populate(ElementInterface $element, array $data): void { /** @var Entry $element */ $element->title = $data['title']['rendered']; $element->slug = $data['slug']; // Import related media if (!empty($data['featured_media'])) { $assetId = $this->command->import('media', $data['featured_media']); $element->setFieldValue('featuredImage', [$assetId]); } // Import ACF fields if present if (!empty($data['acf'])) { $acfFields = $this->command->fieldsForEntity('post_type', 'product'); $values = $this->command->prepareAcfFieldValues($acfFields, $data['acf']); $element->setFieldValues($values); } // Set post date if (!empty($data['date_gmt'])) { $element->postDate = new \DateTime($data['date_gmt']); } } public function find(array $data): ?ElementInterface { // Return existing element to update instead of creating duplicate return Entry::find() ->section('products') ->slug($data['slug']) ->one(); } public function prep(): void { // Create section/fields before import starts $sectionsService = Craft::$app->getSections(); if (!$sectionsService->getSectionByHandle('products')) { // Create products section... } } } ``` -------------------------------- ### Run WP Import CLI Command Source: https://github.com/craftcms/wp-import/blob/main/README.md Initiates the WordPress content import process via the Craft CMS CLI. Prompts for WordPress site URL and credentials. Can be extended with options for specific item types, IDs, and update behavior. ```sh ddev craft wp-import ddev craft wp-import --type=post --item-id=123,789 ddev craft wp-import --type=post --item-id=123 --update ddev craft wp-import --help ``` -------------------------------- ### Advanced WordPress Import Options (CLI) Source: https://context7.com/craftcms/wp-import/llms.txt Utilize advanced options for the WordPress to Craft CMS import CLI tool, including dry runs for testing, failing fast on errors, and controlling pagination. ```bash # Dry run (rollback at end) ddev craft wp-import --dry-run # Fail on first error instead of continuing ddev craft wp-import --fail-fast # Pagination control ddev craft wp-import --type=post --page=2 --per-page=50 ``` -------------------------------- ### Register Custom Components Source: https://context7.com/craftcms/wp-import/llms.txt This section details how to register custom importers, block transformers, and ACF adapters by listening to specific events within the WP Import command. ```APIDOC ## Register Custom Components via Events ### Description Register custom importers, block transformers, and ACF adapters by subscribing to events dispatched by the `craft\wpimport\Command` class. ### Method PHP Event Listener ### Endpoint N/A (Configuration) ### Parameters N/A ### Request Example ```php // config/app.php or plugin/module use craft\events\RegisterComponentTypesEvent; use craft\wpimport\Command; use yii\base\Event; if (class_exists(Command::class)) { // Register custom importer Event::on( Command::class, Command::EVENT_REGISTER_IMPORTERS, function(RegisterComponentTypesEvent $event) { $event->types[] = \config\wpimport\importers\Product::class; $event->types[] = \config\wpimport\importers\Review::class; } ); // Register custom block transformer Event::on( Command::class, Command::EVENT_REGISTER_BLOCK_TRANSFORMERS, function(RegisterComponentTypesEvent $event) { $event->types[] = \config\wpimport\blocktransformers\CustomCallout::class; $event->types[] = \config\wpimport\blocktransformers\VideoEmbed::class; } ); // Register custom ACF adapter Event::on( Command::class, Command::EVENT_REGISTER_ACF_ADAPTERS, function(RegisterComponentTypesEvent $event) { $event->types[] = \config\wpimport\acfadapters\StarRating::class; $event->types[] = \config\wpimport\acfadapters\PostRelationship::class; } ); } ``` ### Response N/A ``` -------------------------------- ### Configure DDEV for Cross-Project Communication Source: https://github.com/craftcms/wp-import/blob/main/README.md Enables communication between a Craft CMS project and a locally hosted WordPress project using DDEV. This involves creating a specific docker-compose file to link the router services. ```yaml services: web: external_links: - "ddev-router:my-wordpress-project.ddev.site" ``` -------------------------------- ### Import WordPress Media and Assets using WP Import Command Source: https://context7.com/craftcms/wp-import/llms.txt Import WordPress media (attachments) into Craft CMS assets. The command handles downloading the file, preserving alt text, captions, descriptions, and upload dates, and linking the uploader to an imported Craft user. ```php // Import WordPress media/attachment $assetId = $this->command->import('media', 999); // Creates Craft asset with: // - Downloaded file in uploads volume // - Alt text from WP // - Caption and description fields // - Original upload date preserved // - Uploader linked to imported user ``` -------------------------------- ### Import Specific Content Types (CLI) Source: https://context7.com/craftcms/wp-import/llms.txt Import specific content types from WordPress to Craft CMS via the CLI. Allows importing single or multiple types, specific items by ID, and updating existing content. ```bash # Import only posts ddev craft wp-import --type=post # Import multiple specific types ddev craft wp-import --type=post,page,media # Import specific items by ID ddev craft wp-import --type=post --item-id=123,456,789 # Update existing content (re-import) ddev craft wp-import --type=post --item-id=123 --update ``` -------------------------------- ### Built-in Block Transformers Reference Source: https://context7.com/craftcms/wp-import/llms.txt This section lists the built-in block transformers available in the WP Import plugin for parsing and transforming WordPress block content. ```APIDOC ## Built-in Block Transformers Reference ### Description This section details the available block transformers that process WordPress Gutenberg blocks into a structured format suitable for Craft CMS. ### Method N/A (Internal processing) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A *(Note: Specific block transformers are typically registered via events, similar to custom importers. Refer to the custom component registration section for details on extending this functionality.)* ``` -------------------------------- ### Built-in Importers Reference Source: https://context7.com/craftcms/wp-import/llms.txt This section provides reference for the built-in importers available in the WP Import plugin for various WordPress content types. ```APIDOC ## Built-in Importers Reference ### Posts and Pages Import WordPress posts, pages, and custom post types using the `import` command. #### Example Usage: ```php // Imports WordPress posts (default post type) $this->command->import('post', 123); // Imports WordPress pages $this->command->import('page', 456); // Custom post types auto-discovered from REST API $this->command->import('product', 789); // Custom post type slug $this->command->import('portfolio', 101); ``` ``` ```APIDOC ### Media and Assets Import WordPress media and attachments, creating Craft assets with associated metadata. #### Example Usage: ```php // Import WordPress media/attachment $assetId = $this->command->import('media', 999); ``` #### Resulting Craft Asset: - Downloaded file stored in the uploads volume. - Alt text populated from WordPress. - Caption and description fields mapped. - Original upload date preserved. - Uploader linked to the imported Craft user. ``` ```APIDOC ### Users Import WordPress users into Craft CMS, mapping roles and preserving registration dates. #### Example Usage: ```php // Import WordPress user $userId = $this->command->import('user', 5); ``` #### Resulting Craft User: - Username, email, and name are imported. - Roles are mapped (e.g., WordPress 'Administrator' to Craft 'Admin'). - Registration date is preserved. - Users will be prompted to reset their password on first login. ``` ```APIDOC ### Taxonomies Import terms from WordPress taxonomies, including built-in and custom ones. #### Example Usage: ```php // Import category term $categoryId = $this->command->import('category', 12); // Import tag $tagId = $this->command->import('post_tag', 34); // Custom taxonomies $termId = $this->command->import('product_category', 56); ``` ``` ```APIDOC ### Comments Import WordPress comments, with support for threaded comments and integration with the Verbb Comments plugin. #### Example Usage: ```php // Import comment (requires Verbb Comments plugin) $commentId = $this->command->import('comment', 789); ``` #### Resulting Craft Comment: - Comment text is imported. - Author is linked to an imported user or set as guest. - Threaded comments are supported (parent comments are mapped). - Comment date and status are preserved. ``` -------------------------------- ### WordPress REST API Extensions Source: https://context7.com/craftcms/wp-import/llms.txt This section outlines the custom REST API endpoints provided by the WP Import Helper plugin to fetch data from WordPress. ```APIDOC ## WordPress Helper Plugin API ### Description Extends the WordPress REST API with endpoints designed for use with the Craft CMS WP Import plugin. ### Method GET ### Endpoint `/wp-json/craftcms/v1/ping` ### Parameters None ### Request Example None ### Response #### Success Response (200) - **pong** (boolean) - Indicates if the API is responsive. ``` ```APIDOC ### Method GET ### Endpoint `/wp-json/craftcms/v1/info` ### Description Retrieves ACF field group configurations and site settings like permalink structure, color palette, and WYSIWYG toolbars. ### Parameters Requires admin authentication. ### Request Example `Authorization: Basic base64(username:app_password)` ### Response #### Success Response (200) - **field_groups** (array) - An array of ACF field group objects, each containing `key`, `title`, `location`, and `fields`. - **permalink_structure** (string) - The permalink structure of the WordPress site. - **color_palette** (array) - The color palette configuration. - **wysiwyg_toolbars** (object) - The WYSIWYG editor toolbar configuration. ``` ```APIDOC ### Method GET ### Endpoint `/wp-json/craftcms/v1/post/{id}` ### Description Fetches a specific WordPress post by its ID, returning the full post object with all its fields, regardless of post type. ### Parameters - **id** (integer) - Required - The ID of the post to retrieve. Requires admin authentication. ### Request Example `Authorization: Basic base64(username:app_password)` ### Response #### Success Response (200) - (object) - The full WordPress post object, including all its fields. ``` ```APIDOC ### Method GET ### Endpoint `/wp/v2/posts/{id}?context=edit` ### Description Retrieves a post with additional parsed block content and ACF data, typically used for editing purposes. ### Parameters - **id** (integer) - Required - The ID of the post to retrieve. ### Request Example None ### Response #### Success Response (200) - **id** (integer) - The post ID. - **content** (object) - Contains `raw` and `rendered` versions of the post content. - **content_parsed** (array) - An array of parsed block objects (added by the helper plugin). - **acf** (object) - Contains Advanced Custom Fields data if ACF is enabled. ``` -------------------------------- ### Register Custom Components via Events in Craft CMS Source: https://context7.com/craftcms/wp-import/llms.txt Register custom importers, block transformers, and ACF adapters in Craft CMS by listening to specific events dispatched by the WP Import Command class. This allows for extending the import functionality with custom logic. ```php // config/app.php or plugin/module use crafteventsRegisterComponentTypesEvent; use craftwpimportCommand; use yiiaseEvent; if (class_exists(Command::class)) { // Register custom importer Event::on( Command::class, Command::EVENT_REGISTER_IMPORTERS, function(RegisterComponentTypesEvent $event) { $event->types[] = \config\wpimport\importers\Product::class; $event->types[] = \config\wpimport\importers\Review::class; } ); // Register custom block transformer Event::on( Command::class, Command::EVENT_REGISTER_BLOCK_TRANSFORMERS, function(RegisterComponentTypesEvent $event) { $event->types[] = \config\wpimport\blocktransformers\CustomCallout::class; $event->types[] = \config\wpimport\blocktransformers\VideoEmbed::class; } ); // Register custom ACF adapter Event::on( Command::class, Command::EVENT_REGISTER_ACF_ADAPTERS, function(RegisterComponentTypesEvent $event) { $event->types[] = \config\wpimport\acfadapters\StarRating::class; $event->types[] = \config\wpimport\acfadapters\PostRelationship::class; } ); } ``` -------------------------------- ### Render Gutenberg Blocks to HTML (PHP) Source: https://context7.com/craftcms/wp-import/llms.txt Convert WordPress Gutenberg blocks into HTML compatible with CKEditor using the wp-import API. Handles various block types and nested structures. ```php use craft\elements\Entry; $entry = Entry::find()->one(); $wpContent = [ [ 'blockName' => 'core/paragraph', 'attrs' => [], 'innerHTML' => '

Hello world

', 'innerBlocks' => [], ], [ 'blockName' => 'core/image', 'attrs' => ['id' => 789], 'innerHTML' => '
', 'innerBlocks' => [], ], ]; // Converts Gutenberg blocks to CKEditor-compatible HTML $html = $this->command->renderBlocks($wpContent, $entry); // Returns: '

Hello world

...' ``` -------------------------------- ### Import WordPress Users using WP Import Command Source: https://context7.com/craftcms/wp-import/llms.txt Import WordPress users into Craft CMS. The command maps user roles, preserves registration dates, and sets up password reset requirements for the first login. It creates Craft users with their username, email, and name. ```php // Import WordPress user $userId = $this->command->import('user', 5); // Creates Craft user with: // - Username, email, name // - Role mapping (admin → Admin, etc.) // - Registration date preserved // - Password reset required on first login ``` -------------------------------- ### WordPress REST API Endpoints for Craft CMS WP Import Source: https://context7.com/craftcms/wp-import/llms.txt Exposes WordPress data via REST API endpoints for use with the Craft CMS WP Import plugin. Includes endpoints for pinging, retrieving site info (field groups, config), and fetching posts by ID. Authentication is handled via Basic Auth for sensitive endpoints. ```http // Ping endpoint (no auth required) GET https://example.com/wp-json/craftcms/v1/ping // Response: {"pong": true} // Get ACF field groups and site config (requires admin auth) GET https://example.com/wp-json/craftcms/v1/info Authorization: Basic base64(username:app_password) // Response: { // "field_groups": [ // { // "key": "group_abc123", // "title": "Product Fields", // "location": [[{"param": "post_type", "operator": "==", "value": "product"}]], // "fields": [ // {"key": "field_xyz", "name": "price", "type": "number", ...}, // {"key": "field_def", "name": "sku", "type": "text", ...} // ] // } // ], // "permalink_structure": "/%postname%/", // "color_palette": [...], // "wysiwyg_toolbars": {...} // } // Get any post by ID regardless of type (requires admin auth) GET https://example.com/wp-json/craftcms/v1/post/123 Authorization: Basic base64(username:app_password) // Returns full post object with all fields // Parsed blocks added to all post types GET https://example.com/wp-json/wp/v2/posts/123?context=edit // Response includes: // { // "id": 123, // "content": {"raw": "...", "rendered": "

..."}, // "content_parsed": [ // Added by helper plugin // {"blockName": "core/paragraph", "attrs": {}, "innerHTML": "...", "innerBlocks": []} // ], // "acf": {...} // If ACF enabled // } ``` -------------------------------- ### Import WordPress Posts and Pages using WP Import Command Source: https://context7.com/craftcms/wp-import/llms.txt Utilize the `import` command within the WP Import plugin to import various WordPress content types. This includes default posts, pages, and custom post types discovered via the REST API. Each import action returns an ID representing the created Craft CMS entry. ```php // Imports WordPress posts (default post type) $this->command->import('post', 123); // Imports WordPress pages $this->command->import('page', 456); // Custom post types auto-discovered from REST API $this->command->import('product', 789); // Custom post type slug $this->command->import('portfolio', 101); ``` -------------------------------- ### Transform Accordion Block with Inner Blocks - PHP Source: https://context7.com/craftcms/wp-import/llms.txt Transforms a custom 'accordion' Gutenberg block into a Craft CMS HTML structure. It iterates through inner 'accordion-item' blocks, extracting their titles and rendering their content. Dependencies include the `craftelementsEntry` and `craftwpimportBaseBlockTransformer` classes. The input is an array of block data and a Craft CMS Entry object. The output is an HTML string. ```php namespace config\wpimport\blocktransformers; use craft\elements\Entry; use craft\wpimport\BaseBlockTransformer; class Accordion extends BaseBlockTransformer { public static function blockName(): string { return 'custom/accordion'; } public function render(array $data, Entry $entry): string { $html = '

'; // Process nested accordion-item blocks foreach ($data['innerBlocks'] as $innerBlock) { if ($innerBlock['blockName'] === 'custom/accordion-item') { $title = $innerBlock['attrs']['title'] ?? ''; $content = $this->command->renderBlocks( $innerBlock['innerBlocks'], $entry ); $html .= sprintf( '
%s
%s
', htmlspecialchars($title), $content ); } } $html .= '
'; return $html; } } ``` -------------------------------- ### Handle ACF Post Relationship Field with Entries - PHP Source: https://context7.com/craftcms/wp-import/llms.txt Creates a custom ACF adapter to map a WordPress 'relationship' ACF field to a Craft CMS Entries field. This adapter handles post type mapping, relation counts, and normalizes WordPress post IDs to Craft entry IDs by importing related posts. Dependencies include `craftaseFieldInterface`, `craft ieldsEntries`, and `craftwpimportBaseAcfAdapter`. Input for `create` is ACF field data, and for `normalizeValue` is an array of WordPress post IDs. ```php // config/wp-import/acfadapters/PostRelationship.php namespace config\wpimport\acfadapters; use craft\base\FieldInterface; use craft\fields\Entries; use craft\wpimport\BaseAcfAdapter; class PostRelationship extends BaseAcfAdapter { public static function type(): string { return 'relationship'; } public function create(array $data): FieldInterface { $postTypes = $data['post_type'] ?? ['post']; return new Entries([ 'name' => $data['label'], 'handle' => $data['name'], 'minRelations' => $data['min'] ?? null, 'maxRelations' => $data['max'] ?? null, 'sources' => $this->getSectionSources($postTypes), ]); } public function normalizeValue(mixed $value, array $data): mixed { // $value is array of WordPress post IDs [123, 456, 789] if (!is_array($value)) { return []; } $entryIds = []; foreach ($value as $wpPostId) { try { // Import each related post and get Craft entry ID $postType = $this->getPostTypeForId($wpPostId); $entryIds[] = $this->command->import($postType, $wpPostId); } catch (\Throwable $e) { // Skip if post can't be imported continue; } } return $entryIds; } private function getSectionSources(array $postTypes): array { // Map WordPress post types to Craft sections // Implementation details... } private function getPostTypeForId(int $wpPostId): string { // Determine post type from ID // Implementation details... } } ``` -------------------------------- ### Custom Block Transformer: Create nested entry for complex block in PHP Source: https://context7.com/craftcms/wp-import/llms.txt A block transformer that handles a 'custom/video-embed' Gutenberg block. Instead of directly rendering HTML, it creates a nested Craft CMS entry to store video details such as URL, caption, and autoplay settings. This approach is useful for complex blocks with structured data that benefits from being managed as separate Craft elements. ```php // config/wp-import/blocktransformers/VideoEmbed.php namespace config\wpimport\blocktransformers; use craft\elements\Entry; use craft\wpimport\BaseBlockTransformer; class VideoEmbed extends BaseBlockTransformer { public static function blockName(): string { return 'custom/video-embed'; } public function render(array $data, Entry $entry): string { $videoUrl = $data['attrs']['url'] ?? ''; $caption = $data['attrs']['caption'] ?? ''; $autoplay = $data['attrs']['autoplay'] ?? false; // Create nested entry for non-HTML data return $this->command->createNestedEntry($entry, function($nestedEntry) use ($videoUrl, $caption, $autoplay) { $nestedEntry->setTypeId($this->getVideoEntryTypeId()); $nestedEntry->setFieldValues([ 'videoUrl' => $videoUrl, 'caption' => $caption, 'autoplay' => $autoplay, ]); }); // Returns: '' } private function getVideoEntryTypeId(): int { // Get or create entry type for video blocks // Implementation details... } } ``` -------------------------------- ### Extend WP Import with Custom Block Transformers Source: https://github.com/craftcms/wp-import/blob/main/README.md Provides a template for creating custom block transformer components for the Craft CMS WP Import plugin. These components are responsible for converting Gutenberg block data and should extend the `BaseBlockTransformer` class. Place custom transformers in `config/wp-import/blocktransformers/`. ```php namespace craft\wpimport\blocktransformers; use craft\wpimport\BaseBlockTransformer; class MyCustomBlockTransformer extends BaseBlockTransformer { // ... implementation ... } ``` -------------------------------- ### Import WordPress Comments using WP Import Command Source: https://context7.com/craftcms/wp-import/llms.txt Import WordPress comments into Craft CMS, requiring the Verbb Comments plugin. The command creates Craft comments, preserving text, author, threading, date, and status. It can link authors to imported Craft users or handle guest authors. ```php // Import comment (requires Verbb Comments plugin) $commentId = $this->command->import('comment', 789); // Creates Craft comment with: // - Comment text // - Author (imported user or guest) // - Parent comment (threaded) // - Date and status ``` -------------------------------- ### Custom Block Transformer: Transform Gutenberg block to HTML in PHP Source: https://context7.com/craftcms/wp-import/llms.txt A custom block transformer for Craft CMS that converts a specific Gutenberg block ('my-plugin/callout') into custom HTML. It extracts attributes like 'type' and 'title' and uses the block's inner HTML to render a styled callout div. This allows for dynamic rendering of WordPress Gutenberg blocks within Craft. ```php // config/wp-import/blocktransformers/CustomCallout.php namespace config\wpimport\blocktransformers; use craft\elements\Entry; use craft\wpimport\BaseBlockTransformer; class CustomCallout extends BaseBlockTransformer { public static function blockName(): string { return 'my-plugin/callout'; // WordPress block name } public function render(array $data, Entry $entry): string { // $data structure: // [ // 'blockName' => 'my-plugin/callout', // 'attrs' => ['type' => 'warning', 'title' => 'Note'], // 'innerHTML' => '
...
', // 'innerBlocks' => [], // ] $type = $data['attrs']['type'] ?? 'info'; $title = $data['attrs']['title'] ?? ''; $content = $data['innerHTML']; return sprintf( '

%s

%s
', $type, htmlspecialchars($title), $content ); } } ``` -------------------------------- ### Prepare ACF Field Values for Craft CMS (PHP) Source: https://context7.com/craftcms/wp-import/llms.txt Normalize WordPress Advanced Custom Fields (ACF) data into a Craft CMS-compatible format using the wp-import API. Maps ACF fields to their Craft CMS equivalents. ```php // ACF data from WordPress REST API $wpAcfData = [ 'hero_image' => 456, // WordPress attachment ID 'publish_date' => '20240115', // ACF date format 'author_info' => [ // ACF group 'name' => 'John Doe', 'bio' => 'Writer...', ], ]; // ACF field definitions from WordPress $acfFields = $this->command->fieldsForEntity('post_type', 'article'); // Normalize values to Craft-compatible format $craftValues = $this->command->prepareAcfFieldValues($acfFields, $wpAcfData); // Returns: [ // 'heroImage' => [123], // Craft asset ID in array // 'publishDate' => DateTime object, // 'authorInfo' => ['name' => 'John Doe', 'bio' => 'Writer...'] // ] $entry->setFieldValues($craftValues); ``` -------------------------------- ### Import Single Item via API (PHP) Source: https://context7.com/craftcms/wp-import/llms.txt Import a single item of a specific WordPress content type and ID using the wp-import extension's API. Returns the created or found Craft CMS element ID. ```php use craft\wpimport\Command; // Get command instance (in your custom importer/transformer) $elementId = $this->command->import( 'media', // WordPress content type slug 12345, // WordPress item ID ['include_drafts' => true] // Optional query params ); // Import returns the created/found Craft element ID $asset = \craft\elements\Asset::find()->id($elementId)->one(); ``` -------------------------------- ### Extend WP Import with Custom Importers Source: https://github.com/craftcms/wp-import/blob/main/README.md Defines the structure for creating custom importer components in Craft CMS's WP Import plugin. Custom importers should extend the `BaseImporter` class and can be placed in the `config/wp-import/importers/` directory. ```php namespace craft\wpimport\importers; use craft\wpimport\BaseImporter; class MyCustomImporter extends BaseImporter { // ... implementation ... } ``` -------------------------------- ### Import WordPress Taxonomies using WP Import Command Source: https://context7.com/craftcms/wp-import/llms.txt Import terms from WordPress taxonomies, including built-in ones like categories and tags, as well as custom taxonomies. The command returns the ID of the newly created Craft CMS term. ```php // Import category term $categoryId = $this->command->import('category', 12); // Import tag $tagId = $this->command->import('post_tag', 34); // Custom taxonomies $termId = $this->command->import('product_category', 56); ``` -------------------------------- ### Map ACF Star Rating Field to Craft Number Field - PHP Source: https://context7.com/craftcms/wp-import/llms.txt Creates a custom ACF adapter to map a WordPress 'star_rating' ACF field to a Craft CMS Number field. It defines the ACF field type and handles the creation and normalization of the field's value. Dependencies include `craftaseFieldInterface`, `craft ieldsNumber`, and `craftwpimportBaseAcfAdapter`. The input for `create` is an array representing the ACF field definition, and for `normalizeValue` is the raw field value from WordPress. ```php // config/wp-import/acfadapters/StarRating.php namespace config\wpimport\acfadapters; use craft\base\FieldInterface; use craft\fields\Number; use craft\wpimport\BaseAcfAdapter; class StarRating extends BaseAcfAdapter { public static function type(): string { return 'star_rating'; // ACF field type } public function create(array $data): FieldInterface { // $data is ACF field definition from WordPress // [ // 'key' => 'field_abc123', // 'name' => 'product_rating', // 'label' => 'Product Rating', // 'type' => 'star_rating', // 'instructions' => '...', // 'max_stars' => 5, // ] $field = new Number([ 'name' => $data['label'], 'handle' => $data['name'], 'instructions' => $data['instructions'] ?? '', 'min' => 0, 'max' => $data['max_stars'] ?? 5, 'decimals' => 1, ]); return $field; } public function normalizeValue(mixed $value, array $data): mixed { // Convert WordPress value to Craft format // $value is from WordPress REST API (e.g., "4.5") return (float) $value; } } ``` -------------------------------- ### Extend WP Import with Custom ACF Adapters Source: https://github.com/craftcms/wp-import/blob/main/README.md Illustrates how to create custom ACF adapter components for the Craft CMS WP Import plugin. These adapters map ACF fields to Craft fields and handle value conversion. Custom adapters must extend `BaseAcfAdapter` and be placed in `config/wp-import/acfadapters/`. ```php namespace craft\wpimport\acfadapters; use craft\wpimport\BaseAcfAdapter; class MyCustomAcfAdapter extends BaseAcfAdapter { // ... implementation ... } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.