View difference between Paste ID: eyeQ9QvR and CiY2X98n
SHOW: | | - or go back to the newest paste.
1
function get_specified_month($uri) {
2
	// Look for patterns like 2099-12 at the end of the URI
3
	$month_pattern = '[0-9]{4}-[0-9]{2}';
4
	$optional_slash = '/?';
5
	$pattern = "#($month_pattern)($optional_slash)$#";
6
7
	// Check for matches
8
	$match = array();
9
	if (preg_match($pattern, $uri, $match) !== 1) return false;
10
11
	// We are interested only in the year/date portion
12
	return $match[1];
13
}
14
15
function upcoming_single_month_view(WP_Query $query) {
16
	// We are only interested in requests to view upcoming events
17
	if ($query->query_vars['eventDisplay'] !== 'upcoming') return;
18
19
	// Has a specific month been specified?
20
	$month = get_specified_month($_SERVER['REQUEST_URI']);
21
	if ($month === false) return;
22
23
	// Set the start date, end date
24-
	$args = &$query->query_vars;
24+
	$query->query_vars['start_date'] = $month.'-01';
25-
	$args['start_date'] = $month.'-01';
25+
	$query->query_vars['end_date'] = $month.'-31';
26-
	$args['end_date'] = $month.'-31';
26+
27
28-
	return $query;
28+
29
add_filter('parse_tribe_event_query', 'upcoming_single_month_view', 20);