It’s about the ordering of images vie the menu_order field.
I like to give the wordpress standard field menu_order a default value like 50. Would like to get it done via MLA Simple Mapping Hooks and the custom field Update Menu Order. A user can easily build a simple sorting with 49 – 50 – 51
Currently I can’t get this done. Can you give me some hints?
I am struggeling with the custom fields. Do I need to enter ‘Update Menu Order’ or do I enter ‘update_menu_order’.
Do I create the custom field with the Add New Custom Field Rule option.
I am more or less familiar with coding the function.php of our child theme.
Good to hear from you again. Thanks for taking the time to find and install and activate the “MLA Simple Mapping Hooks” example plugin. You can use it to set the
menu_orderfield to 50 by defining the following IPTC/EXIF mapping rule:
- Go to the Settings/Media Library Assistant IPTC/EXIF tab.
- If you want to apply the rule to new items as they are uploaded, check the “Enable IPTC/EXIF Mapping when adding new media” and “Enable IPTC/EXIF Mapping when updating media metadata” boxes.
- Scroll down to the “Add New Custom Field Rule” section on the left side of the page.
- Click “Enter new field” to enter the custom field name manually.
- In the “Name” text box, enter
update_menu_orderexactly as shown.
- In the “IPTC Value” dropdown control leave the default, “- None (select a value) -” value in place.
- In the “EXIF/Template Value” text box, enter
template:50. This sets the default value of 50
- In the “Priority” dropdown, select “EXIF”.
- In the “Existing Text” dropdown, select “Replace” to replace the current field content. You can’t select “Keep” because every item has a value; “0” is the WordPress default.
- In the “Status” text box, 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 “Menu Order” 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 your custom rule. This may take a while.
The first two methods will apply all active IPTC/EXIF rules to the selected item(s). This won’t be a problem if you have only the one rule, but the third method might be the best for your application.
CAUTION: This method replaces all existing values. If existing items have non-default values they will be lost. If that’s a problem you can replace only the default “0” values by using the following template:
template:[+menu_order,replace( '/^ $/', 50 )+]. The pattern is five characters: slash, caret, space, dollar sign, slash. MLA translates the “0” to a single space (for internal reasons) before applying the “replace” format code.
I hope that gets you the results you need. I am marking this topic resolved, but please update it if you have problems or further questions about the above suggestions. If you want to consider adding custom code to your theme’s
functions.phpfile, contact me by email to pursue that option.
David. It works pretty well in case of a manual update as described by you. It is not updating the field menu_order during any upload. Standard approach for upload images is
a) creating a post and inserting images into a worpdress galerie
b) creating a post and inserting images into a envira galerie
Thanks for your update and for working with me by email to resolve the problem you found. The plugin logic was not active for Gutenberg Block operations because they do not use the AJAX protocol.
I have uploaded a new MLA Development Version dated 20220309 that corrects the defect you reported. You can find step-by-step instructions for using the Development Version in this earlier topic:
You already have the updated code on your system so you don’t need to install the new Development Version.
This fix will be part of my next MLA version. Thanks for alerting me to this MLA defect.
Some of my users wants to use the filename for ordering purposes, e.g. 01-filenamex.jpg, then 02-filenamey.jpg and so on.
- Is it possible to get the first 2 numbers into the field update_menu_order via a content template.
- Ideally putting 50 into it, if the 2 first digits actually are letters
- can I use a separator instead a fixed number?
Thank you for your thoughts
Good to hear from you again. Thanks for your patience in awaiting my response.
You can update the template in your mapping rule for
update_menu_orderto extract one or more leading digits from the file name that contains a separator to something like this:
template:[+name_only,extract('/^(\\d+)-.*/',1)+]|[+menu_order,replace( '/^ $/', 50 )+]
extractportion of the template matches leading digits (
^(\\d+)followed by a dash and, if found, puts the digits in sub pattern 1. If the result is not empty it is used for the field value. The second part of the template replaces empty values by 50, as in the earlier posts above.
Please post an update and let me know how this works for you. Thanks!
Hi David. Please apologize my delay in getting back to you. Many thanks and it worksup to 99%. Just in case the original filename starts with an underscore the numerical expression is not taken over into the update_menu_order field. But no problem with it. This happens very seldom, we can live with that. Many thanks, I am happy with your solution.
Thanks for your update with the good news.
You wrote “ Just in case the original filename starts with an underscore the numerical expression is not taken over into the update_menu_order field.”
On my system WordPress removes leading underscores from the name and the mapping rule is working as intended. Can you post an example of an image that is not working for you. and let me know what WordPress version you are using? I am happy to investigate further.
Thanks for your example and for working with me by email to resolve the issue. I added the File Renaming on Upload plugin to my system and was able to reproduce your problem.
The File Renaming on Upload plugin by default changes underscores to dashes, so your filename became “25–4180132” (25 dash dash 4180132). I found a bit of code in MLA that applies the WordPress
wptexturize()function to the file data sources, so the
[+name_only+]data source became “25–4180132” (25 ampersand pound 8211 semicolon 4180132) because two dashes changed to an en-dash. That change caused the pattern match to fail. Note that the text in this post is run through
wptexturize()so I can’t show the actual filename values.
I think the use of
wptexturize()for the file data sources is a mistake, so I am removing it in my next MLA update. Thank you for uncovering this MLA issue.
In the interim you can continue to use the File Renaming on Upload plugin if you simply remove the underscore from the “Besides whitespace…” conversion list.
- The topic ‘Using MLA Plugin ‘Simple Mapping Hooks’’ is closed to new replies.