• Resolved ellabtz

    (@ellabtz)


    Hello David,

    I hope you are doing well!

    I need help again regarding my travel agency website. My client now wants to include a gallery that dynamically displays posts for the current month. I have seen that this could be done with ‘monthnum’, but here it depends on the ‘uploaded on-date’. However he wants to do this by using categories January, February … December.
    So now, for example, should automatically display the posts with the category February.

    Is there with your plugin the possibility to do it this way or do you possibly have another solution suggestion?

    Thank you for your help!

    Best Regards

    The page I need help with: [log in to see the link]

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

    (@dglingren)

    Good to hear from you again, and thanks for a stimulating question. As you outlined, the “Simple Date Parameters” only work with the Uploaded on date, and the more powerful ‘Date and Time Queries, the “date query” ‘ is limited to the four dates stored in the wp_posts database table. The simple date parameters also require absolute numeric values; entering a relative format such as “this month” causes a fatal PHP error due to a lack of sanitization in the WordPress code.

    So, there are two problems to be solved. First, how to use a “relative format” to avoid changing the query each month, and second, how to query something other than the wp_posts fields. The first problem can be solved by adding one or more “Field-level data sources” as described in the Settings/Media Library Assistant Documentation tab. The second problem is more difficult because it requires altering the SQL queries generated by WordPress.

    Your client’s suggestion to use Category terms is a reasonable solution that avoids the second problem, but I suggest adding the year to the term values, e.g., “February 2022” or “M202202” so the solution will work over the long run.

    I will investigate the work required (probably modest) to add one or more data sources to solve the first problem and post an update here when I have progress to report. Thanks again for your question and for your continued interest in the plugin.

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your patience while I worked on adding the current date and time data sources. I have uploaded a new MLA Development Version dated 20220207 that contains the updated code. You can find step-by-step instructions for using the Development Version in this earlier topic:

    PHP Warning on media upload with Polylang

    Once the Development Version is installed you can try any of these parameters to match a taxonomy term to the current month and year:

    attachment_category="{+current_timestamp,timestamp( 'F Y' )+}"
    attachment_category="{+current_datetime,date( 'F Y' )+}"
    attachment_category="{+current_getdate(month)+} {+current_getdate(year)+}"
    

    Today, for example, all three forms return “February 2022”. You can find more information in the “Field-level data sources” section of the Settings/Media Library Assistant Documentation tab.

    The updated code will be part of my next MLA version, but in the interim it would be great if you could install the Development Version and let me know if it works for you. Thanks for your patience and understanding while I worked on these issues.

    Thread Starter ellabtz

    (@ellabtz)

    Hi David,

    Thank you very much for your help and programming the desired function!!

    Just installed the development version and tested the new code – works great!
    Thats the code I used:
    attachment_category="{+current_timestamp,timestamp( 'F Y' )+}"

    All files with the category “February 2022″ are displayed here automatically.
    (Here in the first section you can see the gallery: https://www.reisebuero-bamberg.de/testseite-portfolio/

    Thanks for your always great and fast help!

    • This reply was modified 3 years, 1 month ago by ellabtz.
    Plugin Author David Lingren

    (@dglingren)

    I have released MLA version 2.99, which contains the enhancements developed for this topic.

    I am marking the topic resolved, but please update it if you have any problems or further questions regarding the new features. Thanks for inspiring this MLA enhancement.

    Plugin Author David Lingren

    (@dglingren)

    For MLA users who come across this topic in the future I am adding a partial solution to the second problem, “how to query something other than the wp_posts fields. The “MLA UI Elements Example” plugin supports some simple date-based queries on the content of a custom field.

    To install (or update) the example plugin, navigate to the Settings/Media library Assistant Documentation tab and click the “Example Plugins” button. Type “elements” in the text box and click “Search Plugins” to filter the table.

    You are looking for the “MLA UI Elements Example” plugin. Find that plugin and hover over the title in the left-most column. Click the “Update” (or “Install”) rollover action, then go to the WordPress Plugins/Installed Plugins submenu and verify or activate the example plugin as you would any other plugin.

    Once the example plugin is installed you can follow these examples:

    You can use the [mla_gallery] parameters by themselves to filter a gallery display by date values. This is particularly useful when you want to filter based on a date held in a custom field, which the core WordPress date parameters and date query do not support. For example, if you have a custom field named “Publication Date” and want to display what was published in 2020 you can code something like:

    [mla_gallery post_parent=all archive_parameter_name=muie_current_archive muie_current_archive="custom:Publication Date,Y(2020)"]
    

    Note the use of post_parent=all to overide the default display of items attached to the current post/page. You can use the current_timestamp, current_datetime and current_getdate field-level data sources to, for example, return items published in the current month. Code something like:

    [mla_gallery post_parent=all archive_parameter_name=muie_current_archive muie_current_archive="custom:Publication Date,M({+current_datetime,date( 'Ym' )+})"]
    

    By adjusting the format code you can specify any of the four archive types: daily ‘Ymd’, weekly ‘YW’, monthly ‘Ym’, yearly ‘Y’.

    These features are part of the [muie_archive_list] shortcode. Once the plugin is installed you can find more information in the Settings/MLA UI Elements Documentation tab.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Dynamically displays posts for the current month’ is closed to new replies.