• Resolved geertwil

    (@geertwil)


    I’m working on a website for our brass band and I want every musician to see all scores for his instrument. In MLA I created a custom field ‘Instrument’. All the media files have the same naming rules applied: title_instrument.pdf. For example: Sway_Tenorsax (Bb).pdf of Second Waltz_Trompet 1 (Bb).pdf. In MLA custom fields I added a custom field rule with the following settings:
    Name: Instrument
    Data Source: Post_Title
    Meta/template: [+post_title,([^]+)(.+)+] (here chatgpt suggested me tens of other combinations, but none of them worked°
    Existing text: replace
    Format: own
    Option; text
    Status: active

    I have chatting with chapgt, Copilot and Gemini, but result is always the same: If I navigate MLA Assistent and select a few files en click on Bulk Actions, Change en Translate Custom Field Metadata, allways the full post_title is returned to the Instrument field.
    I must be doing something wrong, but I have no idea what.
    Any help is appreciated.
    Kind Regards
    Geert Willemarck

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author David Lingren

    (@dglingren)

    Thanks for your question, and for including the details on your mapping rule; very helpful.

    I am happy that I have not been entirely replaced by AI chatbots. Here is a template that will give you better results:

    Name: Instrument
    Data Source: -- Template (see below) --
    Meta/template: [+name_only,extract( '/(.*)_(.*)/' )+]([+matches:2+])
    Existing text: Replace
    Format: Native
    Option: Text
    Delete NULL Values: checked
    Status: active

    You must set the Data Source to -- Template (see below) -- so MLA will process the template. The template provided starts with the name_only data source (the name portion of the file name); more reliable than the WordPress post_title data source. The extract( '/(.*)_(.*)/' ) format/option suffix divides the name into two subpatterns: 1. title and 2. instrument, discarding the underscore that separates them. The extract suffix puts the subpatterns into an array of matches. The ([+matches:2+]) data source returns the second subpattern content, if present.

    You can add a second rule to save the title portion of the file name by changing the last part of the template to ([+matches:1+]), the first subpattern.

    You can find more information about MLA’s regular expression features in the “Regular Expression Features” section of the Settings/Media Library Assistant Documentation tab. Note, however, that the “named subpatterns” outlined in the documentation do not currently work in mapping rules. That is an MLA defect I will correct in my next update, and I am glad this topic helped me uncover the problem.

    I hope that gives you a solution for your application. I am marking this topic resolved, but please update it if you have any problems or further questions regarding the above suggestions. Thanks for your interest in the plugin.

    Thread Starter geertwil

    (@geertwil)

    Hi David
    Thank you very very very much for your answer. Your solution works perfectly. It puts an end to my days‑long search. I finally have time again to eat and sleep.
    Your plugin is fantastic.
    Kind regards
    Geert Willemarck

Viewing 2 replies - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.