Posted: July 11, 2017 at 10:39 am
|
I had a working extension for my theme’s featured slider, to show specific EE events. This stopped working after an update, so I went to investigate. I receive the following database error:
What seems to be the problem is that the I attempted to use the following function to add it:
and I added this to the query: I even tried to return this in the function: I used code from this page Not sure if this will fix the problem, but either way, can anyone get me in the right direction for this fix? Thanks! |
Hi Ruben, The code from the reference has a number of important checks before it adds the extra WHERE and JOIN, and it also passes in the full SQL (e.g. line 18) then adds to the SQL (on either lines 21 or 23), then returns the full SQL with modification (line 25). Your code is wiping out the SQL completely then replacing with a portion of SQL. If you follow the code example very closely you’ll get back on the right direction. |
|
|
I’ve taken a closer look, and I’m still getting nowhere.
I can see that the join function adds the given SQL code, regardless of using Only using the where part (still) gives me the missing JOIN, which is to be expected. To be sure, I have events that match the query, so its not failing due to having no matches. Still I only get a 500 error and no specific error output when the join is used. I’ve walked through the checks, but none seem to matter to my case. I’ve tried it with Can you see the issue? I’m at a loss. To me it seems the query is correct, but the data returned creates an error. When I use the (expected) query directly in the database, there are no issues. |
You really do need some conditional checks before filtering the query because the posts_where() and posts_join() hooks are applied to every query WP makes for posts. It may help if you can post the entire code in a gist or pastebin, it’s not clear from your code examples here at what point in the request that the code is executing. |
|
|
Hi Josh, I’ve placed the featured.php code on pastebin: https://pastebin.com/77Se8tzT Is it right to assume that the non-existence of checks does not interfere with the query? i.e. I can leave out the checks until the code provides the right posts for the featured slider? Many thanks again! I’ll continue to try and find out what’s going on, and hope that you can easily shed light on some mistake I’m making. |
Hi Ruben, You’ll need to run your code earlier. The trouble you’re having right now is quite likely caused by the time your template gets to your functions that callback on posts_where and posts_join, those two filter hooks have already fired and are done. Along with that, EE_Event_List_Query is deprecated. I can suggest using the built in models system to do the querying. You can follow the example code from this gist: |
|
The support post ‘Query only where the first datetime is on or after today (2)’ 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.