JacquesMivi
March 14, 2017 at 8:33 am
Hello,
I want a custom loop with archived events. I use the following code. But How can i merge this with a classic loop ?
Gett all ids of archived events
//first get all events that have datetimes where its not expired.
$exclude_query[0] = array(
'Datetime.DTT_EVT_end' => array(
'>', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_end' )
)
);
$exclude_event_ids = EE_Registry::instance()->load_model( 'Event' )->get_all_wpdb_results( $exclude_query, OBJECT_K, 'Event_CPT.ID' );
$exclude_event_ids = array_keys( $exclude_event_ids );
//Grab all events where the Datetime end date is less than today (expired) excluding the events we pulled in above.
$where_params['AND'] = array(
'Datetime.DTT_EVT_end' => array( '<', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_end' ) ),
'EVT_ID' => array( 'NOT IN', $exclude_event_ids )
);
$query_params[0] = $where_params;
$expired_event_ids = EE_Registry::instance()->load_model( 'Event' )->get_all_wpdb_results( $query_params, OBJECT_K, 'Event_CPT.ID' );
$expired_event_ids = array_keys( $expired_event_ids );
$ids = array_merge( $ids, $expired_event_ids );
$ids = array_unique( $ids );
Classic loop
if ( ! empty( $wp_query->posts ) ) {
foreach( $wp_query->posts as $post ) : setup_postdata( $post ); ?>
<div class=”search-result”>
//some code to display the events
</div>
<?php
endforeach; wp_reset_postdata();
do_action( ‘genesis_after_endwhile’ );
} else {
?><p>No results found.</p><?php
}
Sorry it seem like a silly question !!
JacquesMivi
March 15, 2017 at 2:44 am
Add New Note to this Reply
Better, night is a good conselor. I improve my code as following.
Now its return stdClass[], How can I have a post ? or better $event_obj ?
global $wp_query, $post;
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
// first get all events that have datetimes where its not expired.
$exclude_query[0] = array(
'Datetime.DTT_EVT_end' => array(
'>', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_end' )
)
);
$exclude_event_ids = EE_Registry::instance()->load_model( 'Event' )->get_all_wpdb_results( $exclude_query, OBJECT_K, 'Event_CPT.ID' );
$exclude_event_ids = array_keys( $exclude_event_ids );
// Grab all events where the Datetime end date is less than today (expired) excluding the events we pulled in above.
$where_params['AND'] = array(
'Datetime.DTT_EVT_end' => array( '<', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_end' ) ),
'EVT_ID' => array( 'NOT IN', $exclude_event_ids )
);
$query_params[0] = $where_params;
$posts = EE_Registry::instance()->load_model( 'Event' )->get_all_wpdb_results( $query_params, OBJECT_K);
//$expired_event_ids = array_keys( $expired_event_ids );
if( !empty( $posts ) )
{
foreach ( $posts as $post ) {
echo "test ";
d($post);
}
}
else
{
?>
<div style="height:400px;text-aligne:center;display:block;padding-top:30px;">
<h3> Aucun résultat associé </h3>
</div>
<?php
}
JacquesMivi
March 15, 2017 at 3:13 am
Add New Note to this Reply
Better, internet is a good conselor. I find this link :
https://eventespresso.com/topic/ee4-past-events-only-list/
JacquesMivi
March 15, 2017 at 7:15 am
Add New Note to this Reply
Better. I obtain the right events, with good order.
Now I just need to insert a tax_query. But its not working.
I following this link : https://eventespresso.com/topic/query-category-order_by-start_date/
$args = array(
'limit' => 10, // 10 per page
'show_expired' => TRUE, // want to include expired events
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'espresso_event_categories',
'field' => 'slug',
'terms' => array($_GET['search-criteria-departement']),
),
array(
'taxonomy' => 'espresso_event_categories',
'field' => 'slug',
'terms' => array($_GET['search-criteria-categorie']),
)
),
'order_by' => 'event_name',
'sort' => 'ASC',
);
// apply the filter to limit primary datetimes to before today
add_filter( 'posts_where', 'custom_posts_where_sql_for_only_expired' );
// the query
global $wp_query;
$wp_query = new EE_Event_List_Query( $args );