MLA CSV Data Source Example. How to upload CSV?
-
Hi,
You say in the documentation:This means that the first step of the process is, of course, uploading the CSV file (or files) you want to use to your Media Library.
I tried to upload the csv file with updates to Media Library but am informed this type of file is not allowed because it’s a security threat.
How / Where do I make this file available to the plugin?Thanks for your help
-
Simple! MLA > settings > Uploads tab
tick “always use MLA MIME type”
Save Changes
Now you can upload a csv file to the Media Library.Hope this helps somebody
Once I’ve uploaded the csv file how do I implement the updates specified in the file.
The documentation describes the csv file in great detail, but doesn’t say how to use it to update image metadata – or am I missing it?
Any help much appreciated.
ThanksRegarding the CSV “security threat”, you have found the solution I proposed in your other topic with this same name:
MLA CSV Data Source Example. How to upload CSV?
Regarding the MLA CSV Data Source Example plugin, the key to using it is understanding that it simply provides an additional “data source” that is used in the same way the other MLA data sources are used. Have a look at the “Field-level Substitution Parameters” section of the Settings/Media Library Assistant Documentation tab. With the example plugin you have a new
csv:
prefix that accesses the columns in your CSV file for use in mapping rules or the[mla_gallery]
shortcode. You can use any column names that make sense for your application. The only special column names are the ones used to match your CSV rows to Media Library items.You asked “how to use it to update image metadata“? You can find information on updating the image metadata in the “Custom Field and Attachment Metadata Processing Options” section of the Documentation tab. There is a “Adding or changing Attachment Metadata” subsection there that includes an example you can adapt for your task.
To update WordPress standard fields like the Title or Description you can use the IPTC/EXIF mapping rules outlined in the “IPTC & EXIF Processing Options” Documentation section. The “EXIF/Template mapping with Content Templates” section will be helpful; you would use the
csv:
prefix in the same way thexmp:
prefix is used in that material.Content templates can also be used in the Bulk Edit area on the Media/Assistant admin submenu to perform one-time bulk editing of fields like Title and Description. The pull-down Help menu on that screen has more specific guidance.
I will leave this topic unresolved for now in case you have problems or further questions regarding the above suggestions.
Hi David,
Does this look like a correct template for the csv file:template:([+csv:base_file,ID,post_title,post_parent,guid+])
I want to update image title and add a redirect to post_parent
Thanks
Thanks for your update with the additional information. It looks like you are trying to do two things:
- Update the Title field for the Media Library item
- Add a redirect to the post/page to which the item is attached
Does that look right? I assume that
base_file,ID,post_title,post_parent,guid
are the field/column names in your CSV file; is that right? I assume that theID
is the field name you are matching on; is that right? To do that you must selectID
in the “Match on” dropdown control found on the Settings/MLA CSV Data General tab. Once that’s done MLA will match the value in the CSV’s ID field to the ID value for each Media Library item and then make the othercsv:
values available for use with that item.Let me try to clarify how this all works. The
csv:
prefix is used with exactly one field name to access one of the fields in your CSV file. For example,[+csv:post_title+]
would access thepost_title
field in your CSV file.To access the
post_title
field you would code something like:template:([+csv:post_title+])
If you want to use this value to replace the Title value for a Media Library item you would define an IPTC/EXIF mapping rule for the Title standard field, or use the template in the Bulk Edit area of the Media/Assistant admin submenu.
I do not understand what you mean by “add a redirect to post_parent”. It looks like you want to compose a gallery of one or more items and make each gallery item a clickable link to the item’s parent. If that’s right you don’t need anything in the CSV file to accomplish your goal. You would use the
page_url
substitution parameter to compose the link for those gallery items. I can give you more specific guidance if you can give me more details of your meaning.Thanks very much for taking the time to explain all this, much appreciated.
So I now have the following:CSV File: ========= Title,ID,post_type Adiantum capillus,39507,attachment Adiantum capillus,39508,attachment CSV MLA Template: ================= template:([+csv:post_title+]) template:([+csv:ID+]) template:([+csv:post_type+]) page_url substitution parameter: ================================ mla_link_href='{+page_url+}' clickable link to the item’s parent: ==================================== https://florapalaestina-ethnobotany.org/?plant=Adiantum-capillus-veneris/
I have a total of around 500 images, the csv file will have a row for each image.
Where do I put the clickable link to each image and how do I apply all this to the images?Thanks
Thanks for your update with the details on your file layout and templates.
Regarding the file layout, I do not see any need for the
post_type
column, but it’s harmless if you have some other purpose for it.I think the only template you need is
template:([+csv:post_title+])
I explain how to use that below.You asked “Where do I put the clickable link to each image“? You don’t need the CSV file or a mapping rule to accomplish this task. The gallery display is generated by the
[mla_gallery]
shortcode. The clickable link is specified as a shortcode parameter. Here is a simple example you can add to a post or page to see how it works:[mla_gallery post_parent=any mla_link_href='{+site_url+}/?p={+post_parent+}']
In this example, the
post_parent=any
will select all of your Media Library images that are attached to a post or page. Themla_link_href=
parameter changes the link assigned to each gallery item. It uses the WordPress “plain permalink” format to link to the item’s parent. You can find more information on each of these parameters in the MLA Gallery sections of the Settings/Media Library Assistant Documentation tab.By the way, my earlier reference to the
{+page_url+}
was incorrect. That value contains the URL of the post/page in which the[mla_gallery]
shortcode is contained. It isn’t helpful for your application, and I regret the confusion.You asked “how do I apply all this to the images“? To replace the default Title value for your Media Library items with the values in your CSV file you need to 1) use the “Edit” Bulk Action on the Media/Assistant admin submenu and enter the template in the “Title” text box on the form, or 2) create and execute an IPTC/EXIF mapping rule. If you want to replace ALL the Title values the mapping rule is the way to go. To do that:
- Go to the Settings/Media Library Assistant IPTC/EXIF tab.
- Locate the “Title” rule entry in the table and click the “Edit” rollover action.
- In the “IPTC Value” dropdown control leave the default “- None (select a value) -” in place.
- In the “EXIF/Template Value” text box enter “template:([+csv:post_title+])” (without the quotes)
- In the “Priority” dropdown, select “EXIF”.
- In the “Existing Text” dropdown, select “Replace” to replace existing default Titles.
- In the “Status” dropdown, select “Active”.
- Scroll down to the bottom of the screen and click “Update”.
Once you define the rule you can apply it to a single item, multiple items or all items:
- To map a single item, go to the Media/Assistant submenu and click the thumbnail of the item you want (or click the “Edit” rollover action) to get the Media/Edit Media screen. You can click the “Map IPTC/EXIF metadata” link to run your rules on this item, then look at the “Title” text box to inspect the results.
- To map two or more items, go to the Media/Assistant submenu and click the checkbox next to the items you want. Then, select “Edit” from the “Bulk Actions” dropdown above the checkboxes and click “Apply” to open the Bulk Edit area. Click the “Map IPTC/EXIF metadata” button to run your rule on the selected items.
- To map all of your items, stay on the Settings/Media Library Assistant IPTC/EXIF tab and click the “Execute” rollover action for the Title rule. This may take a while.
These methods will apply all IPTC/EXIF rules to the selected item(s). This won’t be a problem if you have only the one rule. The third method might be the best for your application. Because your template includes parentheses around the
([+csv:post_title+])
value the rule will only affect items that have a row in the CSV file. You can start small by using a CSV file with one or a small number of rows, then scale it up when you have confidence in the results.I hope that gives you the details you need to complete your application. I will leave this topic unresolved and hope to hear back from you soon.
Hi David,
Thanks for the full explanation.You say
The clickable link is specified as a shortcode parameter.
I’m really interested in updating the media library metadata using the CSV file option.
Is it possible to input this link into the csv file with the post_title, also how would I add a description field for an image into the csv file? What would be the templates?Thanks for your help
I am not sure I understand what you want to accomplish. You wrote “I’m really interested in updating the media library metadata using the CSV file option.” I do not understand what you mean by “the media library metadata“.
The intent of the CSV file as a data source is to let you transfer data from a CSV file into the WordPress database. There are WordPress standard fields like Title, ALT Text, Caption and Description. The mapping rule example I gave in my last post shows you how to transfer a value from the CSV file into a standard field.
WordPress also provides custom fields. You can define a mapping rule to transfer values from the CSV file to a custom field. For images, there is also the “Attachment Metadata” field, which includes details on the intermediate size files WordPress creates as well as an “image_meta” array with some additional values. MLA lets you update or add to these values with a mapping rule.
You asked “how would I add a description field for an image into the csv file?” There is no MLA function to add data to the CSV file itself. You build the CSV file in any way you want, upload it to the Media Library and then take values from the CSV file and put them somewhere in the database.
If you want to update the Description standard field from a value in the CSV file you would create a mapping rule for the Description field in exactly the same way as the Title example I gave in my earlier post.
I hope that helps. If you can tell me more specifically where you want to store the data I can give you more detailed guidance.
Hi David,
I finally succeeded to do what I wanted. Thanks for taking the time to explain all this to me. Here’s the csv I used:Caption,ID "<a href=""https://florapalaestina-ethnobotany.org/?plant=Acacia-farnesiana/"" target=""_blank""><div class=""flex3""><div class=""flex-items""><b>Acacia farnesiana</b></div><div class=""flex-items pad5""> <ul><li>??????? ?????????????</li></ul></div></div><div class=""flex3 pad10""><div class=""flex-items""> <ul><li>Sweet Acacia</li><li> Needle Bush</li></ul></div><div class=""flex-items""> <ul><li>??? ??????</li><li> ??? ??????</li><li> ??? ???</li></ul></div></div></a>",42391 "<a href=""https://florapalaestina-ethnobotany.org/?plant=Acanthus-hirsutus/"" target=""_blank""><div class=""flex3""><div class=""flex-items""><b>Acanthus hirsutus</b></div><div class=""flex-items pad5""> <ul><li>??????? ??????</li></ul></div></div><div class=""flex3 pad10""><div class=""flex-items""> <ul><li>Syrian Bears-breech</li><li> Syrian acanthus</li></ul></div><div class=""flex-items""> <ul><li>??????</li></ul></div></div></a>",42392 "<a href=""https://florapalaestina-ethnobotany.org/?plant=Achillea-arabica/"" target=""_blank""><div class=""flex3""><div class=""flex-items""><b>Achillea arabica</b></div><div class=""flex-items pad5""> <ul><li>?????????? ????????-?????????</li></ul></div></div><div class=""flex3 pad10""><div class=""flex-items""> <ul><li>Yellow Milfoil</li></ul></div><div class=""flex-items""> <ul><li>??????</li><li> ????? ???????</li><li> ???????</li></ul></div></div></a>",39701
and here’s what it looks like
Seems to me that the internet’s one of the few places you can find altruism.
Thanks for making this possibleThanks for the good news about your success and especially for the link to your end results. What a great site and a fascinating project!
I am marking this topic resolved, but please update it if you have any problems or further questions regarding the MLA CSV Data Source Example plugin.
Thanks again for your interest in MLA and for letting me see how it’s being used.
- The topic ‘MLA CSV Data Source Example. How to upload CSV?’ is closed to new replies.