List events for remainder of current month on archive
WordPress Event Management, Calendars & Registration › Forums › General Question › List events for remainder of current month on archive
This topic contains 10 replies, has 2 voices, and was last updated by Ben Harbinson 7 years, 11 months ago.
-
AuthorPosts
-
February 15, 2017 at 4:38 am #26105
I’m having a lot of difficulty trying to list the remaining events for the current month on the event archive page.
I know you can use the month archives (eg. /events/on/2017/02), however I still need to have a generic archive page (just /events/) that I can link to from anywhere in the site.
I’m just using this line of code in archive-events.php to list the events:
<?php eo_get_template_part( 'eo-loop-events' ); //Lists the events ?>
I have tried to create various actions in functions.php
This is far as I have got:
add_action( 'pre_get_posts', 'alter_date_event_archives', 11 ); function alter_date_event_archives( $query ){ if( eventorganiser_is_event_query( $query, true ) ){ $query->set('post_type', 'event'); $query->set('event_start_after', 'today'); $query->set('event_end_before', 'last day of this month'); }
}
The problem is it displays a different number of events than if I go to the actual month archive page PLUS it overrides all the other month pages 🙁
I ALSO have a custom loop at the top of this page to get all categories and list each event under the appropriate category. This works great until the action above which messes up this custom query.
Any help would be appreciated.
Ben HarbinsonFebruary 16, 2017 at 1:58 pm #26129Hi Ben,
What you have will affect all event queries.
Try this instead:
add_action( 'pre_get_posts', 'alter_date_event_archives', 11 ); function alter_date_event_archives( $query ){ // Only change the main query for the events page if( eo_is_event_archive() && $query->is_main_query() ){ // Do not change for the year / month / day events pages if ( eo_is_event_archive( 'year' ) || eo_is_event_archive( 'month' ) || eo_is_event_archive( 'day' ) ) { return; } $query->set('event_start_after', 'today'); $query->set('event_end_before', 'last day of this month'); } }
Stephen HarrisFebruary 16, 2017 at 9:18 pm #26135Thanks Stephen, that works great.
I had to add a function to stop the default WordPress page limit from affecting how many are displayed – this works fine.
For some reason on any of the month archive pages (eg. /events/on/2017/02), it ends on the last day of the month fine, but for some strange reason it always starts from the beginning of the year.
I even tested it with a completely empty functions.php file – same problem.
Ben HarbinsonFebruary 16, 2017 at 11:20 pm #26142So,
/events/on/2017/02
displays all events from 1st January 2017 up to 28th February 2017 and/events/on/2017/03
displays all events from 1st January 2017 up to 31st March 2017? Can you provide a link to the site?Stephen HarrisFebruary 16, 2017 at 11:25 pm #26143Ben HarbinsonFebruary 20, 2017 at 1:16 pm #26159Thanks Ben,
I can’t see any obvious reason why that would happen. Are you able to see what the corresponding SQL query is? That might help identify the problem. You could use a plugin such as Query Monitor.
Stephen HarrisFebruary 20, 2017 at 10:30 pm #26173Hi Stephen,
Here is a link to the page (saved html version) with query monitor enabled, however I can’t work out from this what the issue is.<br />
http://res189.servconfig.com/~healthab/Events_Archive_healthAbility.htmLooking at the Query Vars,
– event_start_after is blank
– event_start_before is 2017-03-31 00:00:00So for some reason it’s not getting the start of the month.
I enabled a blank theme, disabled all other plugins, upgraded to the latest version of eo and the issue still happens.
Appreciate the help.
Ben HarbinsonFebruary 20, 2017 at 11:33 pm #26175Thanks Ben,
Looking at the query variables, anything is correct. That prompted me to look a bit closer at the events.
“Parkinson’s Support” runs: 2nd January 2017 – 2nd January 2018. Looking at the site’s iCal feed. I can see this a recurring event until the end of February 2017, but that each occurrence lasts one year (the initial start and end date are set with a duration of 1 year). This means that each occurrence is runs in the March 2017, and so appears in the
/on/2017/03
page.You can probably see this on the admin calendar – they’ll be a blue block for each occurrence of that event, and it’ll stretch over 1 year.
Stephen HarrisFebruary 20, 2017 at 11:35 pm #26176To clarify, when creating an event you are prompted for a start and end date. You can then repeat the event according to some schedule, until some point (and add/remove additional dates). The initial start and end datetimes, though, refer to the first occurrence. The duration of any additional dates, either generated by the recurrence schedule or added manually will be determined based on the start and end date.
Stephen HarrisFebruary 20, 2017 at 11:35 pm #26177To clarify, when creating an event you are prompted for a start and end date. You can then repeat the event according to some schedule, until some point (and add/remove additional dates). The initial start and end datetimes, though, refer to the first occurrence. The duration of any additional dates, either generated by the recurrence schedule or added manually will be determined based on the start and end date.
Stephen HarrisFebruary 20, 2017 at 11:58 pm #26178Thanks Stephen,
It all makes sense now, the client or someone had loaded in some event dates incorrectly.
Can’t believe I missed that.Thanks for you help.
Ben Harbinson -
AuthorPosts