Support

Home Forums Event Espresso Premium EE show_expired syntax for get_posts

EE show_expired syntax for get_posts

Posted: June 14, 2020 at 1:17 pm

Viewing 3 reply threads


Daniel

June 14, 2020 at 1:17 pm

Hello!

I am trying to get a set of events that are in a category and not expired but my query keeps on showing me expired events.

This is the get_posts() filters I am sending.

Is this the correct syntax for filtering out expired events?


array(6) {
  ["posts_per_page"]=>
  int(15)
  ["post_type"]=>
  string(15) "espresso_events"
  ["orderby"]=>
  string(4) "date"
  ["order"]=>
  string(3) "asc"
  ["show_expired"]=>
  bool(false)
  ["tax_query"]=>
  array(1) {
    [0]=>
    array(2) {
      ["taxonomy"]=>
      string(25) "espresso_event_categories"
      ["terms"]=>
      array(1) {
        [0]=>
        string(3) "352"
      }
    }
  }
}

Everything else here seems to be working. I get a set of event posts in that category.

Thanks in advance for any assistance!


Daniel

June 14, 2020 at 1:23 pm

I found this thread,, but it seems like a lot of extra code on every search just to tune one search…

https://eventespresso.com/topic/expired-events-still-show-up-in-global-search-results-2/

It suggests adding a pre_get_posts filter and detecting something about the query.

Well, if I went this route…. what would I detect about the query I want to modify to show_expired = false? This example is detecting whether it is a search query or not. My query is just a custom query.

Thanks!
D


Tony

  • Support Staff

June 15, 2020 at 8:34 am

Hi Daniel,

Is there a specific reason you are using get_posts() rather than the EE models?

IMO this is much easier with the model system.

$where = array( 
    'Datetime.DTT_EVT_end' => array( '>', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_end' ) ),
    'Term_Taxonomy.term_id' => 21,
);

$events = EEM_Event::instance()->get_all(array($where));

$events now contains an array of all non-expired EE events assigned to the Term with ID 21.

I found this thread,, but it seems like a lot of extra code on every search just to tune one search…

It’s not ‘tuning’ one search, its excluding expired EE events from any ‘main query’ search.

May I ask how else you would prefer to exclude expired EE events from the standard WP search? We have to check its a search query and then include the additional SQL within that query to exclude EE events.

Well, if I went this route…. what would I detect about the query I want to modify to show_expired = false?

You would need to check the query relates to EE events and the show_expired attribute was set, however again, the model system makes this much easier.


Tony

  • Support Staff

June 15, 2020 at 8:42 am

And of course, I forgot to include the category in the example, I’ve updated my above reply to include the term set on the event(s).

Viewing 3 reply threads

The support post ‘EE show_expired syntax for get_posts’ 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