| @@ -39,16 +39,21 @@ | ||
| 39 | 39 | |
| 40 | 40 | $query = new WP_Query( $args ); |
| 41 | 41 | $posts = $query->have_posts() ? $query->posts : array(); |
| 42 | 42 | |
| 43 | + $grid_ids = array(); | |
| 43 | 44 | foreach ( $posts as $grid_post ) |
| 44 | 45 | { |
| 45 | 46 | $grid = new WPUPG_Grid( $grid_post ); |
| 46 | 47 | |
| 47 | 48 | if( in_array( $post_type, $grid->post_types() ) ) { |
| 48 | - $this->generate( $grid->ID() ); | |
| 49 | + $grid_ids[] = $grid->ID(); | |
| 49 | 50 | } |
| 50 | 51 | } |
| 52 | + | |
| 53 | + if( count( $grid_ids ) > 0 ) { | |
| 54 | + update_option( 'wpupg_regenerate_grids_check', $grid_ids ); | |
| 55 | + } | |
| 51 | 56 | } |
| 52 | 57 | |
| 53 | 58 | public function updated_term( $term_id, $taxonomy ) |
| 54 | 59 | { |
| @@ -100,8 +105,16 @@ | ||
| 100 | 105 | update_post_meta( $grid->ID(), 'wpupg_filter', $generated['filter'] ); |
| 101 | 106 | } |
| 102 | 107 | |
| 103 | 108 | public function dynamic_generate( $grid ) { |
| 109 | + // Don't cache term grid | |
| 110 | + if( $grid->type() == 'terms' ) { | |
| 111 | + return array( | |
| 112 | + 'cache' => array(), | |
| 113 | + 'filter' => '', | |
| 114 | + ); | |
| 115 | + } | |
| 116 | + | |
| 104 | 117 | // Get Posts |
| 105 | 118 | $args = array( |
| 106 | 119 | 'post_type' => $grid->post_types(), |
| 107 | 120 | 'post_status' => $grid->post_status(), |
| @@ -164,8 +177,9 @@ | ||
| 164 | 177 | foreach( $taxonomies as $taxonomy ) { |
| 165 | 178 | if( !isset( $posts_per_term[$taxonomy] ) ) $posts_per_term[$taxonomy] = array(); |
| 166 | 179 | |
| 167 | 180 | $terms = wp_get_post_terms( $post_id, $taxonomy ); |
| 181 | + $terms = is_wp_error( $terms ) ? array() : $terms; | |
| 168 | 182 | |
| 169 | 183 | // Get parent terms if enabled |
| 170 | 184 | if( $grid->filter_match_parents() ) { |
| 171 | 185 | $parent_ids = array(); |
| @@ -198,29 +212,41 @@ | ||
| 198 | 212 | |
| 199 | 213 | $post_taxonomy_term_ids = array(); |
| 200 | 214 | |
| 201 | 215 | 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 ); | |
| 216 | + // Check if terms are being limited | |
| 217 | + if( $grid->filter_limit() ) { | |
| 218 | + if( $grid->filter_limit_exclude() ) { | |
| 219 | + if( isset( $limit_terms[$taxonomy] ) && in_array( $term->term_id, $limit_terms[$taxonomy] ) ) continue; | |
| 220 | + } else { | |
| 221 | + if( !isset( $limit_terms[$taxonomy] ) || !in_array( $term->term_id, $limit_terms[$taxonomy] ) ) continue; | |
| 222 | + } | |
| 223 | + } | |
| 204 | 224 | |
| 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 | - } | |
| 225 | + $slug = urldecode( $term->slug ); | |
| 210 | 226 | |
| 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; | |
| 227 | + // Make sure we only handle each term once | |
| 228 | + if( $grid->filter_match_parents() ) { | |
| 229 | + if( in_array( $slug, $handled_terms ) ) continue; | |
| 230 | + $handled_terms[] = $slug; | |
| 231 | + } | |
| 214 | 232 | |
| 215 | - // Terms per post | |
| 216 | - $post_taxonomy_term_ids[] = $slug; | |
| 233 | + // Posts per term | |
| 234 | + if( !isset( $posts_per_term[$taxonomy][$slug] ) ) $posts_per_term[$taxonomy][$slug] = array(); | |
| 235 | + $posts_per_term[$taxonomy][$slug][] = $post_id; | |
| 217 | 236 | |
| 237 | + // Terms per post | |
| 238 | + $post_taxonomy_term_ids[] = $slug; | |
| 239 | + | |
| 240 | + if( !array_key_exists( $slug, $filter_terms ) ) { | |
| 218 | 241 | // Filter terms |
| 219 | 242 | $filter_terms[$slug] = array( |
| 220 | 243 | 'taxonomy' => $taxonomy, |
| 221 | 244 | 'name' => $term->name, |
| 245 | + 'count' => 1, | |
| 222 | 246 | ); |
| 247 | + } else { | |
| 248 | + $filter_terms[$slug]['count']++; | |
| 223 | 249 | } |
| 224 | 250 | } |
| 225 | 251 | |
| 226 | 252 | $terms_per_post[$post_id][$taxonomy] = $post_taxonomy_term_ids; |
| @@ -226,8 +252,41 @@ | ||
| 226 | 252 | $terms_per_post[$post_id][$taxonomy] = $post_taxonomy_term_ids; |
| 227 | 253 | } |
| 228 | 254 | } |
| 229 | 255 | |
| 256 | + // Show Empty Terms | |
| 257 | + if( $grid->filter_show_empty() ) { | |
| 258 | + foreach( $taxonomies as $taxonomy ) { | |
| 259 | + $terms = get_terms( $taxonomy, array( | |
| 260 | + 'hide_empty' => false, | |
| 261 | + ) ); | |
| 262 | + | |
| 263 | + foreach( $terms as $term ) { | |
| 264 | + // Check if terms are being limited | |
| 265 | + if( $grid->filter_limit() ) { | |
| 266 | + if( $grid->filter_limit_exclude() ) { | |
| 267 | + if( isset( $limit_terms[$taxonomy] ) && in_array( $term->term_id, $limit_terms[$taxonomy] ) ) continue; | |
| 268 | + } else { | |
| 269 | + if( !isset( $limit_terms[$taxonomy] ) || !in_array( $term->term_id, $limit_terms[$taxonomy] ) ) continue; | |
| 270 | + } | |
| 271 | + } | |
| 272 | + | |
| 273 | + $slug = urldecode( $term->slug ); | |
| 274 | + | |
| 275 | + if( !isset( $posts_per_term[$taxonomy][$slug] ) ) $posts_per_term[$taxonomy][$slug] = array(); | |
| 276 | + | |
| 277 | + if( !array_key_exists( $slug, $filter_terms ) ) { | |
| 278 | + // Filter terms | |
| 279 | + $filter_terms[$slug] = array( | |
| 280 | + 'taxonomy' => $taxonomy, | |
| 281 | + 'name' => $term->name, | |
| 282 | + 'count' => 0, | |
| 283 | + ); | |
| 284 | + } | |
| 285 | + } | |
| 286 | + } | |
| 287 | + } | |
| 288 | + | |
| 230 | 289 | $cache['taxonomies'] = $posts_per_term; |
| 231 | 290 | $cache['terms'] = $terms_per_post; |
| 232 | 291 | |
| 233 | 292 | // Generate Filter |
| @@ -232,9 +291,9 @@ | ||
| 232 | 291 | |
| 233 | 292 | // Generate Filter |
| 234 | 293 | $filter = ''; |
| 235 | 294 | |
| 236 | - if( count( $filter_terms ) > 0 && $grid->filter_type() == 'isotope' ) { | |
| 295 | + if( count( $filter_terms ) > 0 && ($grid->filter_type() == 'isotope' ) || $grid->filter_type() == 'text_isotope') { | |
| 237 | 296 | $filter_style = $grid->filter_style(); |
| 238 | 297 | |
| 239 | 298 | // All Button |
| 240 | 299 | if( $filter_style['isotope']['all_button_text'] ) { |
| @@ -240,10 +299,36 @@ | ||
| 240 | 299 | if( $filter_style['isotope']['all_button_text'] ) { |
| 241 | 300 | $filter .= '<div class="wpupg-filter-item wpupg-filter-isotope-term wpupg-filter-tag- active">' . $filter_style['isotope']['all_button_text'] . '</div>'; |
| 242 | 301 | } |
| 243 | 302 | |
| 244 | - $filter_terms_order = array_keys( $filter_terms ); | |
| 245 | - sort( $filter_terms_order ); | |
| 303 | + $filter_terms_order = array(); | |
| 304 | + | |
| 305 | + if( $filter_style['isotope']['term_order'] == 'alphabetical_taxonomies' || $filter_style['isotope']['term_order'] == 'reverse_alphabetical_taxonomies' ) { | |
| 306 | + // Order alphatically per taxonomy | |
| 307 | + $terms_per_taxonomy = array(); | |
| 308 | + | |
| 309 | + foreach( $filter_terms as $slug => $term ) { | |
| 310 | + $taxonomy = $term['taxonomy']; | |
| 311 | + if( !array_key_exists( $taxonomy, $terms_per_taxonomy ) ) { | |
| 312 | + $terms_per_taxonomy[$taxonomy] = array(); | |
| 313 | + } | |
| 314 | + $terms_per_taxonomy[$taxonomy][] = $slug; | |
| 315 | + } | |
| 316 | + | |
| 317 | + foreach( $terms_per_taxonomy as $taxonomy => $terms ) { | |
| 318 | + sort( $terms ); | |
| 319 | + $filter_terms_order = array_merge( $filter_terms_order, $terms ); | |
| 320 | + } | |
| 321 | + } else { | |
| 322 | + // Order alphabetically by default | |
| 323 | + $filter_terms_order = array_keys( $filter_terms ); | |
| 324 | + sort( $filter_terms_order ); | |
| 325 | + } | |
| 326 | + | |
| 327 | + if( $filter_style['isotope']['term_order'] == 'reverse_alphabetical_taxonomies' || $filter_style['isotope']['term_order'] == 'reverse_alphabetical' ) { | |
| 328 | + $filter_terms_order = array_reverse( $filter_terms_order ); | |
| 329 | + } | |
| 330 | + | |
| 246 | 331 | $filter_terms_order = apply_filters( 'wpupg_grid_cache_filter_isotope_term_order', $filter_terms_order, $grid ); |
| 247 | 332 | |
| 248 | 333 | foreach( $filter_terms_order as $slug ) { |
| 249 | 334 | $options = isset( $filter_terms[$slug] ) ? $filter_terms[$slug] : false; |
| @@ -248,10 +333,20 @@ | ||
| 248 | 333 | foreach( $filter_terms_order as $slug ) { |
| 249 | 334 | $options = isset( $filter_terms[$slug] ) ? $filter_terms[$slug] : false; |
| 250 | 335 | |
| 251 | 336 | 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>'; | |
| 337 | + if( $grid->filter_count() ) { | |
| 338 | + $name = $options['name'] . ' (' . $options['count'] . ')'; | |
| 339 | + } else { | |
| 340 | + $name = $options['name']; | |
| 341 | + } | |
| 342 | + | |
| 343 | + $filter .= '<div class="wpupg-filter-item wpupg-filter-isotope-term wpupg-filter-isotope-term-' . $options['taxonomy'] . ' wpupg-filter-tag-' . $slug . '" data-taxonomy="' . $options['taxonomy'] . '" data-filter="' . $slug . '">' . $name . '</div>'; | |
| 253 | 344 | } |
| 345 | + } | |
| 346 | + | |
| 347 | + if( $grid->filter_type() == 'text_isotope' && WPUltimatePostGrid::is_addon_active('filter-text') ) { | |
| 348 | + $filter .= WPUltimatePostGrid::addon('filter-text')->get_filter( $grid ); | |
| 254 | 349 | } |
| 255 | 350 | } |
| 256 | 351 | |
| 257 | 352 | // Update Metadata |