Support

Home Forums Event Espresso Premium EE4 – Custom loop – Archived events with specific category

EE4 – Custom loop – Archived events with specific category

Posted: March 15, 2017 at 9:48 am

Viewing 3 reply threads


JacquesMivi

March 15, 2017 at 9:48 am

Hello,

I want a loop of archived events with some filter on category/taxonomy. So I use the following code : https://eventespresso.com/topic/query-category-order_by-start_date/

But the taxonomy are not taken. For example, I should have no results for the folowwing url.
https://www.viviarto.com/ateliers-passes/?searchwpquery=&search-criteria-departement=teheran&search-criteria-categorie=ecriture

Here is the code.

/* 
* Custom Event Espresso to exclude people
*/
function custom_posts_where_sql_for_only_expired() {
return ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end < "' . current_time( 'mysql', TRUE ) . '" ';
}

/* 
* All the archived events
*/
function get_all_events() {

// load in Event Espresso view helpers so event template tags can be used
EE_Registry::instance()->load_helper( 'Event_View' );

$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 );

// the loop
if( have_posts() ) {

// loop through posts
echo '<table class="table-events">';
while ( have_posts() ) : the_post();
html_event($post);
endwhile; 
echo '</table>';

// this action already fires automatically if we're NOT on page 1, but only for prev/next
if( 'numeric' === genesis_get_option( 'posts_nav' ) || ( 'numeric' !== genesis_get_option( 'posts_nav' ) && $searchwppage < 2 ) )
do_action( 'genesis_after_endwhile' );
}
remove_filter( 'posts_where', 'custom_posts_where_sql_for_only_expired' );
wp_reset_postdata();
}

Thanks a lot for your help,


JacquesMivi

March 15, 2017 at 10:01 am

Also the archived filter doesn’t work.
add_filter( ‘posts_where’, ‘custom_posts_where_sql_for_only_expired’ );

In this : https://www.viviarto.com/ateliers-passes/?searchwpquery=&search-criteria-departement=teheran&search-criteria-categorie=ecriture

The “Atelier d’improvisation et de développement personnel” should not appear.


Tony

  • Support Staff

March 28, 2017 at 4:12 am

Hi there,

I checked into this and the custom query from above works for me although I placed it within a custom template, if I passed categories in the same way you are the events would show correctly, are you still having problems?

Also the archived filter doesn’t work.
add_filter( ‘posts_where’, ‘custom_posts_where_sql_for_only_expired’ );

That function does not look correct, it should be something like this:

function custom_posts_where_sql_for_only_expired( $sql ) {
	$sql .= ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end > "' . current_time( 'mysql', TRUE ) . '" ';
	return $sql;
}


JacquesMivi

April 3, 2017 at 5:39 am

Its ok. Thanks a lot 🙂

Viewing 3 reply threads

The support post ‘EE4 – Custom loop – Archived events with specific category’ 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