Support » Plugin: Media Library Assistant » Ordering by 'Publication Date' Custom Field

  • Resolved medium-americano

    (@medium-americano)


    Hi

    I have a publication date custom field set up and I would like my media gallery to display the documents with the most recent ones at the top.

    Unfortunately what is happening is that the documents are being displayed by the alphabetical order of the month of the publication date.

    Here is the code:

    [mla_gallery post_mime_type=application/pdf size="icon" attachment_category=policy-and-publications link=file columns=1 meta_key="publication_date" orderby="meta_value" order="desc" mla_rollover_text='{+title+}' numberposts="8"]
    
    [mla_gallery post_mime_type=application/pdf size="icon" attachment_category=policy-and-publications link=file columns=1 meta_key="publication_date" orderby="meta_value" order="desc" mla_rollover_text='{+title+}' numberposts="8" mla_output="paginate_links,prev_next"]

    Ideally, I would like to keep the month names rather than converting them to numbers.

    The page is here: password = fluoride

    Once again, I’m grateful for any assistance

Viewing 3 replies - 1 through 3 (of 3 total)
  • …To clarify, my documents (publication dates) are showing in this order:

    September 2014
    October 2013
    October 2012
    October 2012
    November 2004
    June 2012
    June 2007
    July 2012…

    The first four are actually correct but that’s just a fluke

    Plugin Author David Lingren

    (@dglingren)

    Thanks for an interesting question.

    You don’t say how the “publication date custom field” was created and is maintained. I can offer a solution but it will require converting the field content to a format that will sort correctly, then using an MLA feature to re-format the values when you display them. The orderby parameter can only work with the values it find in the database; it doesn’t have date-specific variations.

    Have a look in the “Field-level option/format values” section of the Settings/Media Library Assistant Documentation tab. In particular, look at the “,date(f)” format value, which is the key to your solution. If your custom field contains values such as “2014:09” you can sort them properly and display them as “September 2014” by coding something like “[+custom:publication_date,date(F Y)+]” in your custom markup template.

    You can also use the “,date(f)” format value to convert your custom field content to the proper format. You can create a custom field mapping rule for the one-time format conversion task:

    1. Navigate to the Settings/Media Library Assistant “Custom Fields” tab.
    2. Scroll down to the “Add a new Mapping Rule” area, since you already have the custom field defined.
    3. In the first dropdown box, select your field name, “publication_date”.
    4. From the Data Source dropdown list, select “- Template (see below) -“.
    5. In the text box below the dropdown enter “[+custom:Archive Date,date(Y:m)+]”. That takes the existing value like “September 2014”, converts it to a Timestamp and then converts it back to the “2014:09” format.
    6. In the “Existing Text” dropdown list, select “Replace”.
    7. In the “Format” dropdown list, select “Native”.
    8. Click the “MLA Column” check box if you want to make the field available in the Media/Assistant submenu table. If you want to edit the field manually, check the “Quick Edit” and perhaps the “Bulk Edit” checkbox as well.
    9. In the “Option:” dropdown list, select “Text”.
    10. Check the “Delete NULL Values” checkbox to save database space for items with no publication_date value.
    11. Click the “Add Rule” button to save your work and run the rule later or click the “Map All Attachments” to run the rule immediately without saving it.

    Once the rule is in place you can use the Media/Edit Media screen to test it on one item or the Media/Assistant Bulk Edit area to test it on a small number of items. When you are satisfied with it, use the “Mar All Attachments” button to run the rule for all your items and complete the work. Once the conversion is complete you will want to delete the rule or set the “Data Source” dropdown to “- None (select a value) -” to prevent the rule from interfering with your ongoing maintenance.

    That should get you started on a solution for your problem. You will have to adapt the solution to your application and workflow, of course.

    I am marking this topic resolved, but please update it if you have any problems or further questions regarding the above suggestions.

    David, you have absolutely nailed it once again!

    I had used the custom fields plugin to create the publication date field and I just had to alter the save format to yymmdd and the display format to yy:mm.

    Thank you so much

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Ordering by 'Publication Date' Custom Field’ is closed to new replies.