Porter_QueryFilter_Base
Location
What it solves
Minimum implementation
class Porter_Filter_UpcomingEvents extends Porter_QueryFilter_Base {
protected string $className = 'upcoming-events';
protected function should_apply_to_main( WP_Query $q ): bool {
return $q->is_post_type_archive( 'event' ) || $q->is_tax( [ 'event-type', 'event-format' ] );
}
protected function filter_args( array $args, array $context ): array {
$args['post_type'] = 'event';
$args['post_status'] = [ 'publish' ];
$args['meta_key'] = 'start_date';
$args['orderby'] = 'meta_value_num';
$args['order'] = 'ASC';
if ( is_singular( 'event' ) ) {
$args['post__not_in'] = [ get_the_ID() ];
}
return $args;
}
}
new Porter_Filter_UpcomingEvents();Required and optional members
Member
Required
Purpose
How it works
filter_args() context
filter_args() contextKey
Value
Usage pattern
Notes
Last updated