2

I'm trying to import nested categories. My JSON is like:

[{"title":"Title""location":[{"Florida":["Key West"]}]}]

I want to be created "Florida" category and nested child "Key West" But plugin offers me to import that like this: https://d.pr/free/i/NvgGOm

Only "Key West" category will be created.

Is it possible to import nested categories? What is the right JSON structure for that?

Additional info:

  • Plugin version: 4.1.2
  • Craft version:3.3.18.4

1 Answer 1

1

I would approach this by splitting up the work into two tasks:

  1. Import the categories and their parent/child relationships first
  2. Import the entries with a flat listing of categories (just the cities is okay).

The structure of the JSON for importing the categories would be something like this:

[
  {
    "state": "Florida",
    "city": "Key West"
  },
  {
    "state": "Florida",
    "city": "Orlando"
  },
  {
    "state": "Florida",
    "city": "Jackonsville"
  },
  {
    "state": "Florida",
    "city": "Miami"
  },
  {
    "state": "Florida",
    "city": "Tampa"
  },
  {
    "state": "Texas",
    "city": "Austin"
  },
  {
    "state": "Texas",
    "city": "Dallas"
  },
  {
    "state": "Texas",
    "city": "San Antonio"
  }
]

I know this is redundant but it works better with how Feed Me loops over the category elements and creates the category if it doesn't exist and then assigns the parent if (and creates it if it doesn't exist).

You want the mapping to look something like this:

mapping fields in Feed Me

When you go to import your entries you only need to include a flat listing of the category titles (cities) and then they'll be mapped to parent state.

2
  • Here's a video with the same approach: craftquest.io/lessons/…
    – CraftQuest
    Jan 14, 2020 at 2:06
  • thanks a lot for your answer and video! But what can I do to assign the right city if I have cities with the same names in different states? Feb 25, 2020 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.