-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add date_query support #77
Conversation
… 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.
…ple string. Whoops.
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.
Thanks for this. It will be a few days before I have the opportunity to review this, but I'm excited to play with it. |
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! |
Add date_query support, props @DrewAPicture
Boom. What were your thoughts on variable if/when support for multiple date queries comes up (assuming it will)? |
I think we should approach it in the same way multiple tax queries are currently done. I'm thinking I'll push this version out once I take care of #75, and then if there's a need for multiple date queries, we can add that in the next version. |
I'm happy to supplement the wiki for the date query stuff added as well. |
That would be great, thank you. |
How to display the posts of only "Current Day"? Please urgent reply |
@Lyallpuria |
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.... thanks |
this code has not worked on my website. if there is any other code, then please tell me |
no working plz. tell new code of today. |
Try I just tested and confirmed that works. If you need additional help resolving your issue, I recommend you hire a developer on Codeable |
Yes working. Thank you. |
[display-posts date_query_after="yesterday"] I have applied the following code and see the result in attached picture |
Spirit, yes its working but please test with category attribute. |
\
I didnt check it with category attr. |
@SpiritSchool Try "List category posts" plugin |
hmmm. I'll. thanks Lyallpuria |
This syntax is working: |
Hi there, 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! Best, |
Hello guys I use in shortcodes date_query_after: But it doesn’t work ! Same for the date_query_before ! Thx a lot for your help JA |
@juanalan Date queries in WordPress are for the published date or modified date. WP Events Manager is likely storing the event date as metadata, so you should use a meta query. Here are some examples: I recommend contacting WP Events Manager to find out the proper meta keys for querying their data. |
hello Billy Thanks again for your help JA |
Those code snippets were functional when written in 2019. I'm not sure if the post type or meta key has changed. The general idea is you need to query based on the post type (ex: |
The post_type is "event_listing" and the event date seems to be "event_start_date" (or "_event_start_date"). |
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):
date
— Serves as a shortcut to setting the 'year', 'month', and 'day' arguments for a given date query struct on the second-level. It accepts either a strictly-formatted 'YYYY-MM-DD' date string or a relative-formatted date string, such as 'Sunday, September 7'. The relative-formatted string is intended as a fallback for the easier-to-sanitize 'YYYY-MM-DD' formatted string and could prove fickle when supplied with too little information.
date_column
— The first of two top-level arguments, this serves as the "global" column to query for all date queries in the date query arrays on the second-level. This defaults to 'post_date'.
date_compare
— The second of two top-level arguments, this serves as the "global" comparison operator for all date queries in the date query arrays on the second-level. This defaults to '='.
date_query_before
— Sets the 'before' argument for a date query on the second level. It accepts either a strictly-formatted date, 'YYYY-MM-DD', or as a fallback, a relative-formatted date string (using the same logic as the
date
attribute).date_query_after
— Sets the 'after' argument for a date query on the second level. Like the
date_query_before
attribute, It accepts either a a strictly-formatted date, 'YYYY-MM-DD', or as a fallback, a relative-formatted date string (using the same logic as thedate
attribute.date_query_column
— Sets the column to query by for the second-level date query. If not set, falls back to the value of
date_column
.date_query_compare
— Sets the comparison operator for the second-level date query. If not set, falls back to the value of
date_compare
.time
— Serves as a shortcut to populating the 'hour', 'minute', and 'second' arguments in the second-level date query. It accepts only a strictly-formatted string in the format of 'HH:MM:SS' or 'HH:MM'. This does NOT have a string falback.
It also introduces a new function,
be_sanitize_date_time()
for handling date and time sanitization, as this logic is reused in 3 or 4 different instances, I thought it best to keep it DRY :)be_sanitize_date_time()
includes a filter though it does not include the early-return-fallback logic at the top.Here are some sample shortcodes:
Query for posts published on a specific date:
Query for posts published after January 1, 2013:
Query for posts published BEFORE today:
Query for posts modified yesterday: