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


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

You must be logged in to reply to this support post. Sign In or Register for an Account

Support forum for Event Espresso 3 and Event Espresso 4.
Documentation for EE3 and EE4
Documentation for Event Espresso 3 Documentation for Event Espresso 4

Status: publish

Updated by  Tony 3 months, 2 weeks ago ago

Topic Tags

Notifications

This topic is: not resolved
Do NOT follow this link or you will be banned from the site!
[gravityform id=80 title=false description=false ajax=false]
<div class='gf_browser_unknown gform_wrapper' id='gform_wrapper_80' ><form method='post' enctype='multipart/form-data' id='gform_80' action='/topic/ee-show_expired-syntax-for-get_posts/'> <div class='gform_body'><ul id='gform_fields_80' class='gform_fields top_label form_sublabel_below description_below'><li id='field_80_1' class='gfield gfield_contains_required field_sublabel_below field_description_below gfield_visibility_visible' ><label class='gfield_label' for='input_80_1' >First name<span class='gfield_required'>*</span></label><div class='ginput_container ginput_container_text'><input name='input_1' id='input_80_1' type='text' value='' class='medium' aria-required="true" aria-invalid="false" /></div></li><li id='field_80_2' class='gfield gfield_contains_required field_sublabel_below field_description_below gfield_visibility_visible' ><label class='gfield_label' for='input_80_2' >Email address<span class='gfield_required'>*</span></label><div class='ginput_container ginput_container_email'> <input name='input_2' id='input_80_2' type='email' value='' class='medium' aria-required="true" aria-invalid="false" /> </div></li><li id='field_80_3' class='gfield gfield_contains_required field_sublabel_below field_description_below gfield_visibility_visible' ><label class='gfield_label' >GDPR Agreement<span class='gfield_required'>*</span></label><div class='ginput_container ginput_container_checkbox'><ul class='gfield_checkbox' id='input_80_3'><li class='gchoice_80_3_1'> <input name='input_3.1' type='checkbox' value='I consent to have this website store my submitted information so they can respond to my inquiry.' id='choice_80_3_1' /> <label for='choice_80_3_1' id='label_80_3_1'>I consent to have this website store my submitted information so they can respond to my inquiry.</label> </li></ul></div></li><li id='field_80_4' class='gfield gform_validation_container field_sublabel_below field_description_below gfield_visibility_visible' ><label class='gfield_label' for='input_80_4' >Name</label><div class='ginput_container'><input name='input_4' id='input_80_4' type='text' value='' autocomplete='off'/></div><div class='gfield_description' id='gfield_description_80_4'>This field is for validation purposes and should be left unchanged.</div></li> </ul></div> <div class='gform_footer top_label'> <input type='submit' id='gform_submit_button_80' class='gform_button button' value='Download Now' onclick='if(window["gf_submitting_80"]){return false;} if( !jQuery("#gform_80")[0].checkValidity || jQuery("#gform_80")[0].checkValidity()){window["gf_submitting_80"]=true;} ' onkeypress='if( event.keyCode == 13 ){ if(window["gf_submitting_80"]){return false;} if( !jQuery("#gform_80")[0].checkValidity || jQuery("#gform_80")[0].checkValidity()){window["gf_submitting_80"]=true;} jQuery("#gform_80").trigger("submit",[true]); }' /> <input type='hidden' class='gform_hidden' name='is_submit_80' value='1' /> <input type='hidden' class='gform_hidden' name='gform_submit' value='80' /> <input type='hidden' class='gform_hidden' name='gform_unique_id' value='' /> <input type='hidden' class='gform_hidden' name='state_80' value='WyJbXSIsIjBiNjdjZjkyMDUzOWUxOWY5Y2NiZjIwMzM4YjA1Mjk4Il0=' /> <input type='hidden' class='gform_hidden' name='gform_target_page_number_80' id='gform_target_page_number_80' value='0' /> <input type='hidden' class='gform_hidden' name='gform_source_page_number_80' id='gform_source_page_number_80' value='1' /> <input type='hidden' name='gform_field_values' value='' /> </div> </form> </div><script type='text/javascript'> jQuery(document).bind('gform_post_render', function(event, formId, currentPage){if(formId == 80) {} } );jQuery(document).bind('gform_post_conditional_logic', function(event, formId, fields, isInit){} );</script><script type='text/javascript'> jQuery(document).ready(function(){jQuery(document).trigger('gform_post_render', [80, 1]) } ); </script>
[i]
[i]