Support

Home Forums Event Espresso Premium Past Events Archive – SQL Errors and Broken Past Event Search

Past Events Archive – SQL Errors and Broken Past Event Search

Posted: February 16, 2016 at 8:41 am


Mike Wilson

February 16, 2016 at 8:41 am

Hi,

WP Version 4.4.2
EE Version 4.8.32.p

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.

WordPress database error Unknown column 'wp_esp_datetime.DTT_EVT_end' in 'where clause' for query SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND wp_esp_datetime.DTT_EVT_end < "2016-02-16 06:56:29" ORDER BY wp_posts.post_date DESC /*

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,
Mike Wilson


Josh

  • Support Staff

February 16, 2016 at 9:27 am

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
https://gist.github.com/joshfeck/e2f6d67f981df6dc01f5
https://gist.github.com/joshfeck/61a9e21bbc9d4111fbdf


Mike Wilson

February 17, 2016 at 8:26 am

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.


Josh

  • Support Staff

February 17, 2016 at 9:07 am

Hi Mike,

Do you have any other functions running on the site that add a filter to the posts_where filter hook?


Mike Wilson

February 17, 2016 at 9:23 am

No.


Josh

  • Support Staff

February 17, 2016 at 10:09 am

Of course. Maybe someone has changed some of the field names in the _esp_datetime table? Have you checked?


Mike Wilson

February 17, 2016 at 11:38 am

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. :/


Josh

  • Support Staff

February 17, 2016 at 11:41 am

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.


Mike Wilson

February 17, 2016 at 11:45 am

Hi,

Sorry I wasn’t clear. Yes, I checked. The table contains the following columns:

DTT_ID
EVT_ID
DTT_EVT_start
DTT_EVT_end
DTT_reg_limit
DTT_sold
DTT_is_primary
DTT_order
DTT_parent
DTT_deleted
DTT_name
DTT_description


Josh

  • Support Staff

February 17, 2016 at 12:36 pm

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.


Josh

  • Support Staff

February 17, 2016 at 1:59 pm

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
remove_filter( 'posts_where', 'custom_posts_where_sql_for_only_expired' );
after the end of the loop.


Mike Wilson

February 17, 2016 at 2:40 pm

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?


Josh

  • Support Staff

February 17, 2016 at 3:33 pm

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:

if ($event instanceof EE_Event) {
// use methods here
}


Mike Wilson

February 18, 2016 at 12:30 pm

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:

$active_status = $post->EE_Event->get_active_status();
echo $active_status;

But… when I run a search from the archive page using:

<input type="hidden" name="post_type" value="espresso_events" />

I get an error:

Fatal error: Call to a member function get_active_status() on a non-object in /blah/templates/content-espresso_events.php

I can avoid the error by using

$event instanceof EE_Event

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.


Josh

  • Support Staff

February 18, 2016 at 1:07 pm

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.


Mike Wilson

February 19, 2016 at 10:52 am

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.
-Mike


Josh

  • Support Staff

February 19, 2016 at 11:23 am

Hi Mike,

Where you have your code to get the status, you can do something like this:

<?php 
$event = EEH_Event_View::get_event();
if ( $event instanceof EE_Event ){
	$event_status = $event->get_active_status();
} else {
	$event_status = '';
}
?>


Mike Wilson

February 19, 2016 at 12:41 pm

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


Mike Wilson

February 19, 2016 at 12:52 pm

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.


Josh

  • Support Staff

February 19, 2016 at 1:28 pm

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?


Mike Wilson

February 22, 2016 at 8:17 am

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


Josh

  • Support Staff

February 22, 2016 at 11:12 am

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.


Mike Wilson

February 22, 2016 at 11:45 am

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.


Josh

  • Support Staff

February 22, 2016 at 11:55 am

How’s that? Where in your code does it override the default search.php template?


Mike Wilson

February 22, 2016 at 12:09 pm

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.


Josh

  • Support Staff

February 22, 2016 at 12:48 pm

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?


Mike Wilson

February 22, 2016 at 9:03 pm

Hi,

My understanding is

<input type="hidden" <strong>name="post_type</strong>" value="espresso_events">

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


Mike Wilson

February 23, 2016 at 8:49 am

Hi,

It is also worth pointing out that the status banner in fact works on search results.

<span class="ee-status event-active-status-DTE">Expired</span>

I’m just trying to get this (or a similar) class on a different, containing element.


Josh

  • Support Staff

February 23, 2016 at 8:52 am

Mike,

If you input the name of an upcoming event into your search field, does it return any results?


Mike Wilson

February 23, 2016 at 9:02 am

Yes… Search works (and has always worked) as expected. Setting the status ( $event_status = $event->get_active_status(); ) does not return a status.


Josh

  • Support Staff

February 23, 2016 at 12:09 pm

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:

http://josh.eventespresso.com/past-events/


Mike Wilson

February 24, 2016 at 2:12 pm

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”?


Josh

  • Support Staff

February 24, 2016 at 4:27 pm

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.

Event Espresso