@@ -19,6 +19,7 @@ function __construct() {
19
19
add_filter ('jeo_markers_data ' , array ($ this , 'filter_markers ' ), 10 , 2 );
20
20
add_filter ('jeo_geojson_content_type ' , array ($ this , 'content_type ' ));
21
21
add_action ('jeo_markers_before_print ' , array ($ this , 'headers ' ));
22
+ add_action ('pre_get_posts ' , array ($ this , 'pre_get_posts ' ));
22
23
add_action ('template_redirect ' , array ($ this , 'template_redirect ' ));
23
24
}
24
25
}
@@ -90,11 +91,19 @@ function filter_markers($data, $query) {
90
91
return $ data ;
91
92
}
92
93
94
+ function pre_get_posts ($ query ) {
95
+ if (isset ($ query ->query ['geojson ' ])) {
96
+ $ query ->set ('offset ' , null );
97
+ $ query ->set ('nopaging ' , null );
98
+ $ query ->set ('paged ' , (get_query_var ('paged ' )) ? get_query_var ('paged ' ) : 1 );
99
+ }
100
+ }
101
+
93
102
function template_redirect () {
94
103
global $ wp_query ;
95
104
if (isset ($ wp_query ->query ['geojson ' ])) {
96
- $ query = apply_filters ( ' jeo_geojson_api_query ' , $ this ->query () );
97
- $ this ->get_data ($ query );
105
+ $ query = $ this ->query ();
106
+ $ this ->get_data (apply_filters ( ' jeo_geojson_api_query ' , $ query) );
98
107
exit ;
99
108
}
100
109
}
@@ -118,11 +127,14 @@ function content_type($content_type) {
118
127
119
128
function headers () {
120
129
global $ wp_query ;
121
- if (isset ($ wp_query ->query ['geojson ' ]) && isset ($ _GET ['download ' ])) {
122
- $ filename = apply_filters ('jeo_geojson_filename ' , sanitize_title (get_bloginfo ('name ' ) . ' ' . wp_title (null , false )));
123
- header ('Content-Disposition: attachment; filename=" ' . $ filename . '.geojson" ' );
130
+ if (isset ($ wp_query ->query ['geojson ' ])) {
131
+ header ('X-Total-Count: ' . $ wp_query ->found_posts );
132
+ header ('Access-Control-Allow-Origin: * ' );
133
+ if (isset ($ _GET ['download ' ])) {
134
+ $ filename = apply_filters ('jeo_geojson_filename ' , sanitize_title (get_bloginfo ('name ' ) . ' ' . wp_title (null , false )));
135
+ header ('Content-Disposition: attachment; filename=" ' . $ filename . '.geojson" ' );
136
+ }
124
137
}
125
- header ('Access-Control-Allow-Origin: * ' );
126
138
}
127
139
128
140
function get_api_url ($ query_args = array ()) {
@@ -145,4 +157,4 @@ function jeo_get_api_url($query_args = array()) {
145
157
146
158
function jeo_get_api_download_url ($ query_args = array ()) {
147
159
return $ GLOBALS ['jeo_api ' ]->get_download_url ($ query_args );
148
- }
160
+ }
0 commit comments