Thanks for your post. I regret the trouble you’re having with the date query.
You did not give any examples of what you tried so I can’t comment on your specific problem(s). Here are three examples that are working well on my test system:
<h3>Before Last Year</h3>
[mla_gallery numberposts=8 orderby="date DESC" mla_caption="{+post_date+}" date_query="array( array( 'before' => 'last year' ) )"]
<h3>Year 2020</h3>
[mla_gallery date_query="array( array( 'year' => 2020 ) )"]
<h3>One Year, Before Last Year</h3>
[mla_gallery numberposts=8 orderby="date ASC" mla_caption="{+post_date+}" date_query="array( array( 'before' => 'last year', 'after' => '2 years ago' ) )"]
The second example is closest to your all media posted “last year” requirement. The other two examples translate “last year” and “2 years ago” to a specific date and time, e.g., today the SQL query for example three is:
AND ( ( mladev_posts.post_date > '2019-09-21 15:50:22'
AND mladev_posts.post_date < '2020-09-21 15:50:22' ) )
I can find no way to express a query for “the entire year before the current year”. In particular, DO NOT CODE ANYTHING LIKE date_query="array( array( 'year' => 'last year' ) )" WordPress does not validate the year value and giving it a string causes a fatal PHP error on the post/page where the string appears. You have to delete the post/page and start over from scratch. I learned that the hard way.
You will have to edit the query once each year as part of your new year’s resolutions. You could always use the hooks MLA provides to write a bit of code that does the calculation and updates the query automatically. If that’s of interest I can give you more specific help.
The latest version of the “MLA UI Elements Example” plugin includes a new [muie_archive_list] shortcode for date-based archive lists and dropdown controls. You can find it on the Settings/Media Library Assistant Documentation tab by clicking “Example Plugins”.
I hope that gets you going on formulating date_query values for your application. I am marking this topic resolved, but please update it if you have any problems or further questions regarding the above examples. Thanks for your interest in the plugin.
Thanks david, that really does help me a lot! Thanks for confirming that there’s no real proper way to code anything that does not need to be revised once per year; I ran into the same problem you did.
For sure you can mark this topic is closed, and let me say thanks for the great in-depth support you offer for this plugin. There are very few plugins out there that are free and yet carry the level of complexity and support that this one does.