1

In a project I have a checkbox field called gradeLevels with 3 options (k-5,6-8, and 9-12).

Due to design changes, I need to convert this field into a category field. I've made a new category with the same names (k-5,6-8, and 9-12), but I already have data in all of the entries that uses the old checkbox field.

I poked around in mysql and listed all the columns in craft_fields table, but I don't see the newly created categories field in the list, or any categories/entries field for that matter. I'm guessing associations are stored in a different manner?

Is there a possible way using mysql to map all the string values in the check box fields into the corresponding category in the categories field?

  • Not a full answer, but category field data (along with all other relational field data - assets, users, entries, etc.) is stored in the craft_relations table. – Brad Bell Aug 24 '16 at 22:41
  • As Brad mentioned, Categories are stored much differently than checkboxes. Doing this purely through SQL queries is risky. How many Entries are you dealing with in total? – Lindsey D Aug 24 '16 at 23:00
  • FeedMe plugin imports categories, so you could create an xml template file that outputs your entries and their checkbox values(separated by commas), then use FeedMe to import that file in and map that to your cats. They just have to have the same name or FeedMe will create new ones. Just back up your db! I'm only commenting because I imported categories once on a site and have no real experience trying to do what you want. – AbbeyDesign Aug 24 '16 at 23:29
  • @Lindsey roughly 500 entries. It's okay if I break it during testing because I have many backup copies of the DB. Looks like the checkbox field type is stored as varchar(255) – ChaiTea Aug 24 '16 at 23:34
  • @AbbeyDesign: I was thinking something similar... use Feed Me to create a sort of self-referential loop. I think it's a great idea, you should add it as an official answer! – Lindsey D Aug 24 '16 at 23:46
2

FeedMe plugin imports categories, so you could create an xml template file that outputs your entries and their checkbox values(separated by commas), then use FeedMe to import that file back in and map those checkboxes to your categories. They just have to match spelling, otherwise FeedMe will create a new category

FeedMe

Something like:

<xml>
  <blog>
    {% for entry in entries %}
      <entry>
        <title>{{ entry.title }}</title>{# required for import #}
        <category><![CDATA[{% for option in entry.checkboxFieldHandle %}{{ option }}, {% endfor %}]]></category>
      </entry>
    {% endfor %}
  </blog>
 </xml>
  • ok this doesn't seem to work. I made the xml feed and can access it in the browser. Feed me can pick it up, but when I run the import, the new categories field remains unchanged even when the log says it's successfully updated – ChaiTea Aug 25 '16 at 23:04
  • Did you map it to your categories field in FeedMe? A couple of things that slipped me up when I was doing it...1. make sure devMode is off. 2. in the settings of FeedMe, make sure "Primary element" is set(in my case "entry"). Then maybe check your "Import Strategy" is set to Add and Update existing. – AbbeyDesign Aug 26 '16 at 14:01
  • Ok finally got this working, a big gotcha is that when selecting import options, I had to choose import title field to the title field, otherwise feed me doesn't know which entry is related to which, and just updates one entry over and over again – ChaiTea Sep 15 '16 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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