Home › Forums › Calendar Products › Events Calendar PRO › Hiding past events breaks list pagination.
- This topic has 5 replies, 3 voices, and was last updated 10 years, 6 months ago by
Support Droid.
-
AuthorPosts
-
October 1, 2015 at 11:01 am #1010562
integrity
ParticipantAdding the following to my functions.php file appears to have broken to event list pagination.
add_filter('tribe_events_pre_get_posts', 'filter_tribe_all_occurences', 100); function filter_tribe_all_occurences ($wp_query) { // Only filter tribe-events $post_type = $wp_query->query_vars['post_type']; if ( $post_type == 'tribe_events') { // Uncomment the if statement to show expired events on backend. //if ( !is_admin() ) { $new_meta = array(); $today = new DateTime(); // Join with existing meta_query if(is_array($wp_query->meta_query)) { $new_meta = $wp_query->meta_query; } // Add new meta_query, select events ending from now forward $new_meta[] = array( 'key' => '_EventEndDate', 'type' => 'DATETIME', 'compare' => '>=', 'value' => $today->format('Y-m-d H:i:s') ); $wp_query->set( 'meta_query', $new_meta ); //} } return $wp_query; }Clicking “next” takes me to the second page of events, but on the second page clicking next shows the first page of events. Any subsequent clicks of “next” do not alter the events shown.
I thought the problem might be outdated code in the theme’s tribe-events template overrides, but removing them did not fix the issue. Commenting out the
add_filter('tribe_events_pre_get_posts', 'filter_tribe_all_occurences', 100);
line does fix the issue, though, which is why I believe the filter somehow interferes with the pagination.October 2, 2015 at 6:53 am #1010874George
ParticipantHey @integrity,
I see that you originally posted about this in another thread, so I unfortunately don’t know how much more helpful I can be here – but to get started:
1. Can you share your system information with us? I will try to recreate your problems based on that. Here’s how to share your System Information → https://theeventscalendar.com/knowledgebase/sharing-sys-info/
2. Also, can you clarify exactly where you found this code?
3. Finally, for now, can you just clarify what your exact goals are for using this code? There may be an alternative method or something for achieving the same thing.
We only provide extremely limited support for custom code, but I’m happy to at least try and help as much as I can here. Addressing these three items in this reply will give us a good foundation for testing and troubleshooting; I look forward to your reply!
— George
October 2, 2015 at 8:37 am #1010950integrity
ParticipantThis reply is private.
October 2, 2015 at 8:49 am #1010965integrity
ParticipantHi George,
1. See private reply.
2. I found the original code snippet here (https://theeventscalendar.com/support/forums/topic/how-to-hide-past-events/). I modified it a bit from that original snippet. I commented out the
if ( !is_admin() )check in order to hide the events from the backend as well. I also added a post_type check because the filter was effecting tribe_venue queries elsewhere on the site.3. The goal: Prevent site visitors from seeing past events. Also hide past events from the WP Dashboard Event view. (This may change to NOT hiding past events from the WP Dashboard Event view, depending on the client’s preference.)
Thanks so much. Let me know if I can provide any further information.
October 5, 2015 at 11:29 pm #1011759George
ParticipantHey @integrity,
I appreciate all of the information you’ve provided here, and also your patience with my slow reply over the weekend and such.
I’m afraid the old snippet shared by Brook, while awesome and helpful at the time, may indeed be breaking things here because we have improved pagination in our plugins. A side-effect of these improvements is perhaps some conflicting code with this snippet.
I should note, however, that the original snippet worked fine for me on my local site. So there just be something about your customizations to the script that are breaking things; to test for this, can you start by replacing your customized version of Brook’s script with the original version? The original version is pasted here:
add_filter('tribe_events_pre_get_posts', 'filter_tribe_all_occurences', 100);
function filter_tribe_all_occurences ($wp_query) {
if ( !is_admin() ) {
$new_meta = array();
$today = new DateTime();// Join with existing meta_query
if(is_array($wp_query->meta_query))
$new_meta = $wp_query->meta_query;// Add new meta_query, select events ending from now forward
$new_meta[] = array(
'key' => '_EventEndDate',
'type' => 'DATETIME',
'compare' => '>=',
'value' => $today->format('Y-m-d H:i:s')
);$wp_query->set( 'meta_query', $new_meta );
}return $wp_query;
}If this does not work, then leave it in place regardless and proceed to the next step, which is update your site’s version of the Events Filterbar plugin. Your site is running version 3.9; it whould be running version 3.12.1, which is the most recent and is available at http://theeventscalendar.com/my-account/downloads.
If updating this alone does not help, then the last thing to check for at this point is your WordPress version. Your “System Information” shows your site to be at version 4.1.8, when the most recent version out there is 4.3.1. Once you update to 4.3.1, have another look at events pagination on your site and see if the issues persist.
I hope all this testing reveals something useful about the nature of your problems here. It could simply be a version conflict with Filterbar being stuck at the outdated version 3.9; or it could be something specific to your tweaks to Brook’s original snippet. It could even be some combination of these things and others.
Regardless, the testing I describe above will be very helpful for getting closer to a solution here. Let me know what you find!
— George
October 20, 2015 at 7:05 am #1016211Support Droid
KeymasterThis topic has not been active for quite some time and will now be closed.
If you still need assistance please simply open a new topic (linking to this one if necessary)
and one of the team will be only too happy to help. -
AuthorPosts
- The topic ‘Hiding past events breaks list pagination.’ is closed to new replies.
