• Resolved DaveFE

    (@davefe)


    Firstly, thanks for creating this plugin. I’ve spent the last few days evaluating loads of gallery-related plugins and yours is the first that is doing what I want and not messing something else up in the process. ??

    Two questions. First to make sure what I’m doing is the best way about it and second is a problem.

    I want to upload a large number of photos (prob. 200 at most) to a post and display a gallery that’s sorted by the EXIF picture taken date. I’ve mapped the created_timestamp to a new custom field I called “taken.” I’m using the MLA shortcode [mla_gallery post_parent=”current” orderby=”meta_value_num asc” meta_key=”taken”]. I’ve searched but can’t see that I can order by the image_meta/created_timestamp directly, is that right?

    And secondly, when I go to Media/Assistant and make the taken custom field visible, then click on the header of the taken column to sort by it, all the media disappears. What am I missing?

    Thanks again!

    https://www.ads-software.com/plugins/media-library-assistant/

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

    (@dglingren)

    Thanks for you appreciative comments; I try hard not to mess anything else up in the MLA process ??

    You might be interested in this earlier support topic about dates and EXIF mappings:

    Modify upload date?

    In particular, the last post in that topic suggests some alternatives to created_timestamp. You might find that the original EXIF data is easier to work with than the Unix timestamp value created by WordPress.

    Your use of a custom field for this application is indeed “the best way around it“. The image_meta/created_timestamp is buried in a serialized array within another custom field and is not available for direct use in sorting or selecting data. That’s exactly why the custom field mapping was added to MLA.

    Thank you for including the source text for your [mla_gallery] shortcode; very helpful. You’re right; the gallery is not getting sorted in the way you want because you have found a small defect in the current MLA version (which I will fix – thanks!). MLA does not handle the meta_value_num case correctly and does not properly account for adding the asc parameter within the orderby clause for custom field sorting.

    When you map created_timestamp to a custom field, MLA converts the value from a number to a CHAR string. If you change your shortcode parameters from orderby="meta_value_num asc" to orderby="meta_value" order="ASC" your created_timestamp values should sort correctly in the current MLA version. If you use any of the original EXIF fields it will also work, and the values displayed in the Media/Assistant submenu table will be readable as well.

    I am not sure what you mean by “all the media disappears” when you sort on the “taken” column in the Media/Assistant submenu table. Do you mean that the table comes back with “No items found.”, or is it that the items with a created_timestamp value are moved or not displayed? What happens if you click on the column header twice (to get a descending sort)? On my test system, sorting by created_timestamp values is working properly.

    Thanks for your questions and for helping me find a small bug. Any additional information you can give me on the disappearing media items would be great.

    Thread Starter DaveFE

    (@davefe)

    Thanks so much for the quick reply!

    MLA does not handle the meta_value_num case correctly and does not properly account for adding the asc parameter within the orderby clause for custom field sorting.

    Actually, my gallery images are being sorted correctly whether I use meta_value_num or meta_value. I suppose I’ll use meta_value since, as you’ve explained, it’s a CHAR string anyway.

    I am not sure what you mean by “all the media disappears” when you sort on the “taken” column in the Media/Assistant submenu table. Do you mean that the table comes back with “No items found.”

    Sorry for my poor explanation. Yes, that’s exactly what I’m seeing. If I go to the Media/Assistant right now it will show all 359 images in my gallery. If I then click on the taken column header, it shows “No items found.” The URL it points to is /wp-admin/upload.php?page=mla-menu&orderby=c_taken&order=asc. I thought perhaps c_taken should be taken so I’ve tried changing it by hand, but then it just sorts the photos in a seemingly random order.

    Plugin Author David Lingren

    (@dglingren)

    Thanks for this update. I did some further investigation and testing. You’re right; the sorting seems to work correctly and I can’t find any bugs in that logic. I regret the confusion caused by my quick reply.

    So far I am mystified by your “No items found.” issue. The URL you posted is correct; the “c_” prefix is how MLA identifies custom fields, which can have arbitrary names. I created a custom field named “taken” and tried sorting by it before and after I mapped the created_timestamp values to it; both are working fine for me.

    Are other columns sorting correctly for you? Can you create some other custom field column that sorts without this issue?

    It’s possible some other plugin you are using is interfering with the MLA logic. Can you tell me what other plugins are active on your site?

    Thank you for your patience and for any additional information you can give me.

    Thread Starter DaveFE

    (@davefe)

    Problem solved!

    Downloaded the Debug Bar plugin to see the interaction with MySQL on the Media/Assistant page. It showed CREATE VIEW command denied for table 'wp_mla_alt_text_view'. Turned out I (for some ODD reason) was missing CREATE VIEW and a couple of other permissions on my WordPress database. Granted all permissions and retried the taken sort and it works fine.

    Thanks so much for your help and sorry for the bother!

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your detective work and for the update with the good news! I can add the database permissions check to my list of things to watch out for.

    I’ll also add the Debug Bar plugin to my toolkit (I’m using the Query Monitor plugin, which is excellent).

    I will mark this issue resolved, but please update it or start another if you have problems or more questions. Thanks for your interest in the plugin.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Sorting by custom field in Media/Assistant not working’ is closed to new replies.