Closed nicktrosnant closed 1 month ago
When the group filter is selected, this is implemented by these lines of code, which place the filter is ‘meta_value’:
public static function filter_posts($query) { //modify the query only if it is admin and main query. if (!(is_admin() && $query->is_main_query())) { return $query; } //only modify query if filter is set for this post type // phpcs:ignore WordPress.Security.NonceVerification.Recommended if (!(($query->query['post_type'] === U3A_EVENT_CPT) && (isset($_GET['groupID']) && !empty($_GET['groupID'])))) { return $query; }
//modify the query_vars for group selection
$query->query_vars['meta_key'] = 'eventGroup_ID';
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$query->query_vars['meta_value'] = sanitize_text_field($_GET['groupID']);
$query->query_vars['meta_compare'] = '=';
return $query;
However, there is also a pre_get_posts function being called which sets the sort order when date is used. This resets the meta_key, so we end up with a query which is looking for a value in ‘eventDate’ which is the group_ID (129).
/**
So... the filter_posts function needs to set a meta_query rather than what it does now. Like this example from the WP_Query class 'meta_query' => array( array( 'key' => 'color', 'value' => 'blue', 'compare' => 'NOT LIKE', ), Note the need for a nesting of arrays here, even though it is a simple query without ANDs or ORs Then meta_key can still be set in the sort function, at least I hope so!
[reported on forum]
Go to the list of all u3a events on the Dashboard, then select a group to filter by, and click on filter. Then click on the event date heading to get them in date order and all the events disappear.
The result is the same using the reverse procedure:
Go to the list of all u3a events on the Dashboard, then click on the event date heading to get all events in date order, then select a group to filter by - then again all the events disappear.