Support

Home Forums Event Espresso Premium query upcoming events with facetwp

query upcoming events with facetwp

Posted: June 18, 2019 at 8:29 pm

Viewing 9 reply threads


dirk.tussing

June 18, 2019 at 8:29 pm

Hi, event espresso team,

I have another problem need some help. We are currently using facetWP for events filtering. The events are queried correctly the first time events on events pages which are all upcoming events, but then upon any filtering, the facetWP query kick in, it’s returning all the espresso events as they are using the default WP_Query.

I couldn’t figure out a way to modify the query so that it only returns the upcoming events.


dirk.tussing

June 18, 2019 at 8:34 pm

events page

espresso events template

facetWP query


Josh

  • Support Staff

June 19, 2019 at 9:27 am

Hi,

In the second screenshot you have code that’s passing show_expired, and that’s not a valid parameter for wp_query. What you could do instead is apply filters to the query. Here’s an example gist that shows how to modify a query using filters on posts_join and posts_where.

https://gist.github.com/joshfeck/ae206b13b751743b08137e72dc55151e


dirk.tussing

June 19, 2019 at 4:29 pm

Hi Josh,

I added the function and applied the filter in the facetWP query directly but the page won’t display anything.

I also tried putting in the function file:
added function and filter in function.php

empty events


dirk.tussing

June 19, 2019 at 5:10 pm

it looks like the SQL is not right. "SELECT SQL_CALC_FOUND_ROWS wp_posts.*, wp_esp_datetime.* , MIN( wp_esp_datetime.DTT_EVT_start ) as event_start_date , MIN( wp_esp_datetime.DTT_EVT_start ) as event_start_date FROM wp_posts INNER JOIN wp_esp_datetime ON ( wp_posts.ID = wp_esp_datetime.EVT_ID ) --->join filter<--- WHERE 1=1 AND wp_posts.ID IN (<1 IDs>) AND wp_posts.post_type = 'espresso_events' AND ((wp_posts.post_status = 'publish')) AND wp_esp_datetime.DTT_EVT_end > '2019-06-19 23:08:15' --->where filter<--- AND wp_esp_datetime.DTT_EVT_end > '2019-06-19 23:08:15' GROUP BY wp_posts.ID LIMIT 0, 14"

Is there a way to clean the query before adding the join and where clause?


Josh

  • Support Staff

June 19, 2019 at 5:20 pm

It looks like you don’t need to add the join and where clause. Do you see how there are two of these?
wp_esp_datetime.DTT_EVT_end > '2019-06-19 23:08:15'

So if you remove the join and where, does one of those remain?

Truth be told, I have not worked with facetwp so I don’t know what’s involved with adding custom queries to its query.


dirk.tussing

June 19, 2019 at 5:32 pm

Yea, but once I start filtering events without the custom filter, the query is back to the simple one where it queries all the espresso events like so: without filter

if I do enable the custom filter, it’s being injected on the first query shown in the screenshot which creates 2 join and where clause.


Josh

  • Support Staff

June 19, 2019 at 6:05 pm

It sounds like you need a way to hook in to the filtered query provided by facetWP (not the initial page load query).


dirk.tussing

June 19, 2019 at 7:13 pm

We are using a workaround at the moment by using the facetWP template on a custom page instead of the archive page. With the filters, it’s working fine now, just still need to find a way to sort it by event date.


Josh

  • Support Staff

June 20, 2019 at 4:24 pm

You may need to do a join on wp_esp_datetime. One thing to be aware of is events can have multiple dates, and in most use cases the date to use would be the next upcoming datetime (start date). Your use case may vary though.

Viewing 9 reply threads

The support post ‘query upcoming events with facetwp’ 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