Skip to content

Commit 6d8c359

Browse files
committed
geojson api pagination fix and set total count on api header
1 parent 11e5824 commit 6d8c359

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

inc/api.php

+19-7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function __construct() {
1919
add_filter('jeo_markers_data', array($this, 'filter_markers'), 10, 2);
2020
add_filter('jeo_geojson_content_type', array($this, 'content_type'));
2121
add_action('jeo_markers_before_print', array($this, 'headers'));
22+
add_action('pre_get_posts', array($this, 'pre_get_posts'));
2223
add_action('template_redirect', array($this, 'template_redirect'));
2324
}
2425
}
@@ -90,11 +91,19 @@ function filter_markers($data, $query) {
9091
return $data;
9192
}
9293

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+
93102
function template_redirect() {
94103
global $wp_query;
95104
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));
98107
exit;
99108
}
100109
}
@@ -118,11 +127,14 @@ function content_type($content_type) {
118127

119128
function headers() {
120129
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+
}
124137
}
125-
header('Access-Control-Allow-Origin: *');
126138
}
127139

128140
function get_api_url($query_args = array()) {
@@ -145,4 +157,4 @@ function jeo_get_api_url($query_args = array()) {
145157

146158
function jeo_get_api_download_url($query_args = array()) {
147159
return $GLOBALS['jeo_api']->get_download_url($query_args);
148-
}
160+
}

style.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Theme URI: https://github.com/cardume/jeo
44
Author: Cardume
55
Author URI: http://www.cardume.art.br/
66
Description: Interactive maps and journalism
7-
Version: 1.0.1
7+
Version: 1.0.2
88
License: GNU General Public License v3 or later
99
License URI: http://www.gnu.org/licenses/gpl-3.0.html
1010
Tags: black, white, green, light, four-columns, two-columns, responsive-layout, translation-ready, theme-options

0 commit comments

Comments
 (0)