I'm building a project with a lot of photo assets organized into sub directories of the main photos asset source. I'm trying to add tags to these assets so they are searchable when I try to use them in my entries.

With native features of Craft, this process seems to be very manual, I just have to click on each of these asset files and add the tags that I want.

Is there a way, either using a plugin or make a MySQL query, to bulk add tags to all the asset files under a certain sub directory?

  • Are the tags based on the subfolder name or something? Or are they going to be more dynamic regardless of what folder they live in?
    – Brad Bell
    Feb 10 '17 at 22:01
  • The tags are supposed to be the same as the subfolder names.
    – ChaiTea
    Feb 14 '17 at 0:12

Seems doable with a custom plugin.

The pseudo-code would be something like:

  1. Use AssetsService to grab all of the files for the source.
  2. Loop through the files and parse the parent folder paths.
  3. Based on the subfolder for the asset, check if an existing tag already exists with the TagsService.
  4. If 3 is true, assign that tag's value to a tag field on the Asset.
  5. If 3 is false, create the tag using the TagsService, then assign that tag's value to a tag field on the Asset.

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.