I am building a site for a personal project and I have a series of Events created via a Custom Post Type.
I then need these events to be displayed by a custom meta value (Event Start Date) and in ASC order. I have managed to figure that out and the code I used is below:
/*CUSTOM ARCHIVE FOR EVENTS*/
function events_pagesize( $query ) {
// exit out if it's the admin or it isn't the main query
if ( is_admin() || ! $query->is_main_query() )
return;
// so its not admin, and its the main query, is it the tr-events post archive?
if ( is_post_type_archive( 'tr-events' ) ) {
// it is!! Set the posts_per_page to 6
$query->set( 'posts_per_page', 4 );
$query->set( 'order' , 'asc' );
$query->set( 'meta_key', 'wpcf-tr-order-date');
$query->set( 'orderby', 'meta_value');
return;
}
}
add_action( 'pre_get_posts', 'events_pagesize', 1 );
My question is how to hide posts past a specific date AND how would I also create an Archive view to display Events that have completed? I've seen tons of posts about this and most options break pagination. This option as a function in the functions.php gets me 70% there.