Posted: February 16, 2016 at 8:41 am
|
Hi, WP Version 4.4.2 You guys previously helped me set up a “past events” archive on our public site. Basically we just separated upcoming events and expired events, as we keep event downloadable materials available for a considerable time after an event ends. You provided some code for templates, which we integrated into our theme. This has worked well for about a year now without issue. Since the last update to version 4.8.32.p we are experiencing a couple of issues: 1. It appears the past events are still being shown properly on the front end, but I have a ton of SQL errors in our logs. It is possible these errors were present previous to the last update, but it was brought to my attention at that time.
2. The past events search is not returning results Previously the search on the past events page successfully searched only past events and returned results as expected. After the update to 4.8.32.p this functionality broke. There are no errors given, it just doesn’t return results. If you guys need to see the templates, I can zip those up and send them via email. I’m also happy to purchase a support token if this is outside of your normal forum support process. I’d like to get this issue solved and get updated to the most recent release as soon as possible. Thank you, |
Hi Mike, I can suggest reviewing these three code examples that show how to query for and display past events only: https://gist.github.com/joshfeck/56bc9e4a3683779fe90f |
|
|
The first gist you linked to is essentially what I’m using now. The function custom_posts_where_sql_for_only_expired() is slightly different from what I had, but updating to the code you provided did not clear up the SQL errors I indicated above. |
Hi Mike, Do you have any other functions running on the site that add a filter to the |
|
|
No. |
Of course. Maybe someone has changed some of the field names in the _esp_datetime table? Have you checked? |
|
|
HI, No one has changed anything in the DB – I’m the only person who would have anyways. I’m getting the same error locally and in PROD. :/ |
But did you check? The error says that wp_esp_datetime doesn’t have a DTT_EVT_end column. It will help to confirm the column is still there. |
|
|
Hi, Sorry I wasn’t clear. Yes, I checked. The table contains the following columns: DTT_ID |
I’m not sure what would cause the post_where filter function to stop working all of a sudden, it continues to function on our test sites that are set up with current versions of EE. One thing you could do is post those templates up into a github gist, then post a link here and we can take a look at them. |
|
This is only a guess, but if you’re running multiple loops on that one page, then that could cause the error you’re seeing in the logs. Which you can avoid by adding |
|
|
I think that was the issue… I was wondering because I was also seeing additional errors like “made by require(‘some_random_template.php’)”. Adding the remove-filter after the loop seems to have cleared up the issue, but I’ll need to do some more testing to be sure. 2. I’m still working on the search issue, but it seems it’s not actually search that’s the problem. Another error on the page is just causing the template to stop processing. I was using $post->EE_Event->is_expired() to set a class on the event containing div, and since the last update, that began throwing an error when searching. Is there a reliable way to add the event status e.g. active, expired, etc to the post_class? |
You can check the get_active_status() method that’s in the EE_Event class. That should be reliable, and it’s also recommended to do a check like this before using EE methods:
|
|
|
Hi, Yea… I’m running into the same issue with get_active_status() as I did with is_expired(). The following returns the status as expected (DTU, DTE, etc.) on the archive template:
But… when I run a search from the archive page using:
I get an error:
I can avoid the error by using
But that’s not helpful, lol. All I really want to do is to get an event-status class on the body or other container so I can hide meta and iCal downloads on expired events. |
Hi Mike, You know what? If you actually had the event object in the first place, you’d avoid the errors you’re seeing. So step one is get the event object, the instanceof check just ensures that you do have it. If you need help with step one, it’d be helpful if you can post your code into a pastebin or gist. |
|
|
Hi Josh, I’ve posted the main templates in a gist here. Let me know if you need more information. Thank you for your help. |
Hi Mike, Where you have your code to get the status, you can do something like this:
|
|
|
Hi Josh, The code you provided doesn’t return a status when using the event search. This is the same issue I already have. It works fine – initially – on the archive-espresso_events.php and the template-past-event-archive.php, but once I perform a search and the search results are displayed on the page (also uses the archive-espresso_events.php template), it returns nothing. -Mike |
|
Hi, Just also FYI – this (and the code I was using before) works on single event pages as well… the only place it doesn’t work, it seems, is through the event search. |
I thought your search results page didn’t return any results. Did you happen to get that working since the time you posted the code earlier? |
|
|
Hi, The call to a member function on a non object error was killing the page rendering before the search results were displayed. This happened with the original code, which used $post->EE_Event->is_expired() and also with the code you suggested – $event->get_active_status(). 1. If I comment out that code the search results render – but without the event status I’m trying to get. 2. If I wrap the call in $event instanceof EE_Event, it of course just steps out and instead of throwing an error and the search results display – but without the event status I’m trying to get. The thing is $event->get_active_status() works great if I just hit the event list or past event list directly, but when I go through the event search and render the search results back to the archive-espresso_events.php template – just like the event list – it breaks. All of this worked prior to version 4.8.32.p – for like the past year or so. Somehow I’m losing access to the even object during the search. – Mike |
After reviewing your code I don’t how it would have printed search results at all, but that may be because I don’t know what your search.php template looks like. |
|
|
The event search results don’t print to search.php. The event search form (which searches only the espresso_event post type) is located on the past events archive page. The search results from this form post back to to archive-espresso_events.php template. |
How’s that? Where in your code does it override the default search.php template? |
|
|
Hi, I don’t have a search.php template in this theme. Global search results post back to the index.php (the blog archive) and post type searches will follow the template hierarchy – in this case, archive-espresso_events.php. There’s no need to override anything. |
Are you sure about that? I’ve not seen it where post type searches follow template hierarchy, and the codex doesn’t indicate this either. Maybe you have a function in your theme’s functions.php file that sets up a redirect to your template when doing a search for that custom post type? |
|
|
Hi, My understanding is
Causes WP to default to archive-{post_type}.php for custom post types as the default search template when no search.php is found. If there is no archive template, then index.php is used. There was a related trac ticket previously, but the “fix” to change the name variable to “type” doesn’t isolate the search to the given post_type, it just includes the post type in the results and kicks out to the default search results page. In my case, it’s desirable to use the archive-espresso_events.php for search results, because it keeps the search in the context of events and keeps the user on the events archive. Also, no, I don’t have a function redirecting searches for events. -Mike |
|
Hi, It is also worth pointing out that the status banner in fact works on search results.
I’m just trying to get this (or a similar) class on a different, containing element. |
Mike, If you input the name of an upcoming event into your search field, does it return any results? |
|
|
Yes… Search works (and has always worked) as expected. Setting the status ( $event_status = $event->get_active_status(); ) does not return a status. |
It returns a status for me when I use the code outlined here. What I did was I took your 4 templates and adapted them into another WordPress theme (you can download it from here and install it on a test server to test it out). It’s also installed on a test server, you can test the search results here: |
|
|
Hi Josh, Thanks for this effort. I’m still trying to sort it out… On the example site, do you have “Display Expired Events” on the events settings set to “no”? |
Yes it’s currently set to No for Display Expired Events. |
|
The support post ‘Past Events Archive – SQL Errors and Broken Past Event Search’ is closed to new replies.
Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.