As requested in #38, this PR implements date_query support for a single date query.
This would be considered "phase 1" with the option to later add support for incremented (multiple) date queries. The reasoning for not including multiples with this PR, is that while the logical progression is to move to supporting multiples in the future, it would probably be best to first nail down the best approach to implementing a single date query in terms of attribute naming and architecture :)
Note: In the attribute descriptions below, you'll notice that I reference the "top-level" and "second-level" areas of the date query. Top-level arguments serve in a "global" capacity to all date queries contained on the second-level. The actual individual date queries are defined on the second-level of the associative array.
This introduces a total of 8 new attributes (yikes, I know):
It also introduces a new function,
Here are some sample shortcodes:
Query for posts published after January 1, 2013:
Query for posts published BEFORE today:
Query for posts modified yesterday:
… helper function, be_sanitize_date_time(), to DRY-up sanitization of date and time strings.
… the simplifcation change two commits ago.
…imes. This opens the door to using 'relative' date and time formats such as 'Wednesday August 6' with the year implied instead of something like '2014-08-06'.
…defined in the beginning.
…r whether the calling argument check can accept a string. This would only work as a fallback for the 'date', 'date_query_before' or 'date_query_after' attributes. The 'date' argument simply serves as a quick shortcut to defining the 'year', 'month', and 'day' arguments for any given date_query array.
…faults as they fallback to the values of the global 'column' and 'compare' arguments in WP_Date_Query.
I'm a little on the fence about the attribute naming. It's clear there needs to be a logical division between the top-level and second-level attributes, though things could easily get pretty long once you start thinking about 1) using multiple date query attributes in a single shortcode 2) eventually incrementing those attributes for multiple date queries.
In the vein of multiple queries, we could probably forgo introducing the second-level
"phase 2" would then introduce
Something to think about.
…ain -. Kind of a weird way to go about it but the explode needs the hyphen to proceed.
I got syntax errors from the variables defined within an if statement. Ex: https://github.com/DrewAPicture/display-posts-shortcode/blob/datequery/display-posts-shortcode.php#L164 Breaking it apart into $variable = whatever; if ( ! empty( $variable ) ) fixed it for me.
But other than that, it worked great!
I have applied in this date code in the following way
[display-posts date="today" category="Dawn" no_posts_message="No Job Published in Dawn Newspapers Today." posts_per_page="150"]
but this is not working so I have applied the following as usual
[display-posts date="2018-12-12" category="Dawn" no_posts_message="No Job Published in Dawn Newspapers Today." posts_per_page="150"]
I am using IsleMag theme and This plugin has not been tested with version of WordPress.
Plz spend your precious time for this issue. And tell me how to fix it....
I have applied the following code and see the result in attached picture
I'm using your plugin (thank you!!) and implemented it as follows:
etc etc, hoping that i would get a list of posts for every day of the week.
The problem is, that during the day some posts move to the column of the previous day (rather than wait until 0:00h).
Do you have any idea what causes this behaviour? If so, is there a solution for it?
Thanks in advance!