PluginProbe
WP Ultimate Post Grid / 2.3
WP Ultimate Post Grid v2.3
4.1.1 trunk 1.5 1.6 1.7 1.7.1 1.7.2 1.8 1.9 2.0 2.1 2.2 2.3 2.4.0 2.5.0 2.6.0 2.7.0 2.8.0 2.8.2 3.0.0 3.3.0 3.4.0 3.5.0 3.6.0 3.7.0 All 32 releases
← All changes | helpers/grid_cache.php +106 -16 1.82.3 View file →
@@ -100,8 +100,16 @@
100 100 update_post_meta( $grid->ID(), 'wpupg_filter', $generated['filter'] );
101 101 }
102 102
103 103 public function dynamic_generate( $grid ) {
104 + // Don't cache term grid
105 + if( $grid->type() == 'terms' ) {
106 + return array(
107 + 'cache' => array(),
108 + 'filter' => '',
109 + );
110 + }
111 +
104 112 // Get Posts
105 113 $args = array(
106 114 'post_type' => $grid->post_types(),
107 115 'post_status' => $grid->post_status(),
@@ -164,8 +172,9 @@
164 172 foreach( $taxonomies as $taxonomy ) {
165 173 if( !isset( $posts_per_term[$taxonomy] ) ) $posts_per_term[$taxonomy] = array();
166 174
167 175 $terms = wp_get_post_terms( $post_id, $taxonomy );
176 + $terms = is_wp_error( $terms ) ? array() : $terms;
168 177
169 178 // Get parent terms if enabled
170 179 if( $grid->filter_match_parents() ) {
171 180 $parent_ids = array();
@@ -198,29 +207,41 @@
198 207
199 208 $post_taxonomy_term_ids = array();
200 209
201 210 foreach( $terms as $term ) {
202 - if( !$grid->filter_limit() || ( isset( $limit_terms[$taxonomy] ) && in_array( $term->term_id, $limit_terms[$taxonomy] ) ) ) {
203 - $slug = urldecode( $term->slug );
211 + // Check if terms are being limited
212 + if( $grid->filter_limit() ) {
213 + if( $grid->filter_limit_exclude() ) {
214 + if( isset( $limit_terms[$taxonomy] ) && in_array( $term->term_id, $limit_terms[$taxonomy] ) ) continue;
215 + } else {
216 + if( !isset( $limit_terms[$taxonomy] ) || !in_array( $term->term_id, $limit_terms[$taxonomy] ) ) continue;
217 + }
218 + }
204 219
205 - // Make sure we only handle each term once
206 - if( $grid->filter_match_parents() ) {
207 - if( in_array( $slug, $handled_terms ) ) continue;
208 - $handled_terms[] = $slug;
209 - }
220 + $slug = urldecode( $term->slug );
210 221
211 - // Posts per term
212 - if( !isset( $posts_per_term[$taxonomy][$slug] ) ) $posts_per_term[$taxonomy][$slug] = array();
213 - $posts_per_term[$taxonomy][$slug][] = $post_id;
222 + // Make sure we only handle each term once
223 + if( $grid->filter_match_parents() ) {
224 + if( in_array( $slug, $handled_terms ) ) continue;
225 + $handled_terms[] = $slug;
226 + }
214 227
215 - // Terms per post
216 - $post_taxonomy_term_ids[] = $slug;
228 + // Posts per term
229 + if( !isset( $posts_per_term[$taxonomy][$slug] ) ) $posts_per_term[$taxonomy][$slug] = array();
230 + $posts_per_term[$taxonomy][$slug][] = $post_id;
217 231
232 + // Terms per post
233 + $post_taxonomy_term_ids[] = $slug;
234 +
235 + if( !array_key_exists( $slug, $filter_terms ) ) {
218 236 // Filter terms
219 237 $filter_terms[$slug] = array(
220 238 'taxonomy' => $taxonomy,
221 239 'name' => $term->name,
240 + 'count' => 1,
222 241 );
242 + } else {
243 + $filter_terms[$slug]['count']++;
223 244 }
224 245 }
225 246
226 247 $terms_per_post[$post_id][$taxonomy] = $post_taxonomy_term_ids;
@@ -226,8 +247,41 @@
226 247 $terms_per_post[$post_id][$taxonomy] = $post_taxonomy_term_ids;
227 248 }
228 249 }
229 250
251 + // Show Empty Terms
252 + if( $grid->filter_show_empty() ) {
253 + foreach( $taxonomies as $taxonomy ) {
254 + $terms = get_terms( $taxonomy, array(
255 + 'hide_empty' => false,
256 + ) );
257 +
258 + foreach( $terms as $term ) {
259 + // Check if terms are being limited
260 + if( $grid->filter_limit() ) {
261 + if( $grid->filter_limit_exclude() ) {
262 + if( isset( $limit_terms[$taxonomy] ) && in_array( $term->term_id, $limit_terms[$taxonomy] ) ) continue;
263 + } else {
264 + if( !isset( $limit_terms[$taxonomy] ) || !in_array( $term->term_id, $limit_terms[$taxonomy] ) ) continue;
265 + }
266 + }
267 +
268 + $slug = urldecode( $term->slug );
269 +
270 + if( !isset( $posts_per_term[$taxonomy][$slug] ) ) $posts_per_term[$taxonomy][$slug] = array();
271 +
272 + if( !array_key_exists( $slug, $filter_terms ) ) {
273 + // Filter terms
274 + $filter_terms[$slug] = array(
275 + 'taxonomy' => $taxonomy,
276 + 'name' => $term->name,
277 + 'count' => 0,
278 + );
279 + }
280 + }
281 + }
282 + }
283 +
230 284 $cache['taxonomies'] = $posts_per_term;
231 285 $cache['terms'] = $terms_per_post;
232 286
233 287 // Generate Filter
@@ -232,9 +286,9 @@
232 286
233 287 // Generate Filter
234 288 $filter = '';
235 289
236 - if( count( $filter_terms ) > 0 && $grid->filter_type() == 'isotope' ) {
290 + if( count( $filter_terms ) > 0 && ($grid->filter_type() == 'isotope' ) || $grid->filter_type() == 'text_isotope') {
237 291 $filter_style = $grid->filter_style();
238 292
239 293 // All Button
240 294 if( $filter_style['isotope']['all_button_text'] ) {
@@ -240,10 +294,36 @@
240 294 if( $filter_style['isotope']['all_button_text'] ) {
241 295 $filter .= '<div class="wpupg-filter-item wpupg-filter-isotope-term wpupg-filter-tag- active">' . $filter_style['isotope']['all_button_text'] . '</div>';
242 296 }
243 297
244 - $filter_terms_order = array_keys( $filter_terms );
245 - sort( $filter_terms_order );
298 + $filter_terms_order = array();
299 +
300 + if( $filter_style['isotope']['term_order'] == 'alphabetical_taxonomies' || $filter_style['isotope']['term_order'] == 'reverse_alphabetical_taxonomies' ) {
301 + // Order alphatically per taxonomy
302 + $terms_per_taxonomy = array();
303 +
304 + foreach( $filter_terms as $slug => $term ) {
305 + $taxonomy = $term['taxonomy'];
306 + if( !array_key_exists( $taxonomy, $terms_per_taxonomy ) ) {
307 + $terms_per_taxonomy[$taxonomy] = array();
308 + }
309 + $terms_per_taxonomy[$taxonomy][] = $slug;
310 + }
311 +
312 + foreach( $terms_per_taxonomy as $taxonomy => $terms ) {
313 + sort( $terms );
314 + $filter_terms_order = array_merge( $filter_terms_order, $terms );
315 + }
316 + } else {
317 + // Order alphabetically by default
318 + $filter_terms_order = array_keys( $filter_terms );
319 + sort( $filter_terms_order );
320 + }
321 +
322 + if( $filter_style['isotope']['term_order'] == 'reverse_alphabetical_taxonomies' || $filter_style['isotope']['term_order'] == 'reverse_alphabetical' ) {
323 + $filter_terms_order = array_reverse( $filter_terms_order );
324 + }
325 +
246 326 $filter_terms_order = apply_filters( 'wpupg_grid_cache_filter_isotope_term_order', $filter_terms_order, $grid );
247 327
248 328 foreach( $filter_terms_order as $slug ) {
249 329 $options = isset( $filter_terms[$slug] ) ? $filter_terms[$slug] : false;
@@ -248,10 +328,20 @@
248 328 foreach( $filter_terms_order as $slug ) {
249 329 $options = isset( $filter_terms[$slug] ) ? $filter_terms[$slug] : false;
250 330
251 331 if( $options ) {
252 - $filter .= '<div class="wpupg-filter-item wpupg-filter-isotope-term wpupg-filter-tag-' . $slug . '" data-taxonomy="' . $options['taxonomy'] . '" data-filter="' . $slug . '">' . $options['name'] . '</div>';
332 + if( $grid->filter_count() ) {
333 + $name = $options['name'] . ' (' . $options['count'] . ')';
334 + } else {
335 + $name = $options['name'];
336 + }
337 +
338 + $filter .= '<div class="wpupg-filter-item wpupg-filter-isotope-term wpupg-filter-tag-' . $slug . '" data-taxonomy="' . $options['taxonomy'] . '" data-filter="' . $slug . '">' . $name . '</div>';
253 339 }
340 + }
341 +
342 + if( $grid->filter_type() == 'text_isotope' && WPUltimatePostGrid::is_addon_active('filter-text') ) {
343 + $filter .= WPUltimatePostGrid::addon('filter-text')->get_filter();
254 344 }
255 345 }
256 346
257 347 // Update Metadata