| @@ -25,83 +25,47 @@ | ||
| 25 | 25 | // Check if we need to filter the grid dynamically |
| 26 | 26 | $dynamic_rules = array(); |
| 27 | 27 | if( count( $options ) > 0 && WPUltimatePostGrid::is_premium_active() ) { |
| 28 | 28 | |
| 29 | - // Term Grid. | |
| 30 | - if ( $grid->type() == 'terms' ) { | |
| 31 | - if( isset( $options['term_id'] ) ) { | |
| 32 | - $term_ids = str_replace( ',', ';', $options['term_id'] ); | |
| 33 | - $term_ids = str_replace( 'current_term', get_queried_object_id(), $term_ids ); | |
| 29 | + if( isset( $options['post_id'] ) ) { | |
| 30 | + $post_ids = str_replace( ',', ';', $options['post_id'] ); | |
| 31 | + $post_ids = str_replace( 'current_post', get_the_ID(), $post_ids ); | |
| 34 | 32 | |
| 35 | - $dynamic_rules = array( | |
| 36 | - 'values' => explode( ';', $term_ids ), | |
| 37 | - 'type' => 'restrict', | |
| 38 | - ); | |
| 39 | - unset( $options['term_id'] ); | |
| 40 | - } | |
| 33 | + $dynamic_rules[] = array( | |
| 34 | + 'post_type' => 'wpupg_general', | |
| 35 | + 'taxonomy' => 'id', | |
| 36 | + 'values' => explode( ';', $post_ids ), | |
| 37 | + 'type' => 'restrict', | |
| 38 | + ); | |
| 39 | + unset( $options['post_id'] ); | |
| 40 | + } | |
| 41 | 41 | |
| 42 | - if( isset( $options['exclude_term_id'] ) ) { | |
| 43 | - $term_ids = str_replace( ',', ';', $options['exclude_term_id'] ); | |
| 44 | - $term_ids = str_replace( 'current_term', get_queried_object_id(), $term_ids ); | |
| 42 | + if( isset( $options['exclude_post_id'] ) ) { | |
| 43 | + $post_ids = str_replace( ',', ';', $options['exclude_post_id'] ); | |
| 44 | + $post_ids = str_replace( 'current_post', get_the_ID(), $post_ids ); | |
| 45 | 45 | |
| 46 | - $dynamic_rules = array( | |
| 47 | - 'values' => explode( ';', $term_ids ), | |
| 48 | - 'type' => 'exclude', | |
| 49 | - ); | |
| 50 | - unset( $options['exclude_term_id'] ); | |
| 51 | - } | |
| 52 | - } else { | |
| 53 | - // Post Grid. | |
| 54 | - if( isset( $options['post_id'] ) ) { | |
| 55 | - $post_ids = str_replace( ',', ';', $options['post_id'] ); | |
| 56 | - $post_ids = str_replace( 'current_post', get_the_ID(), $post_ids ); | |
| 46 | + $dynamic_rules[] = array( | |
| 47 | + 'post_type' => 'wpupg_general', | |
| 48 | + 'taxonomy' => 'id', | |
| 49 | + 'values' => explode( ';', $post_ids ), | |
| 50 | + 'type' => 'exclude', | |
| 51 | + ); | |
| 52 | + unset( $options['exclude_post_id'] ); | |
| 53 | + } | |
| 57 | 54 | |
| 55 | + foreach( $options as $taxonomy => $terms ) { | |
| 56 | + if( taxonomy_exists( $taxonomy ) ) { | |
| 58 | 57 | $dynamic_rules[] = array( |
| 59 | - 'post_type' => 'wpupg_general', | |
| 60 | - 'taxonomy' => 'id', | |
| 61 | - 'values' => explode( ';', $post_ids ), | |
| 58 | + 'post_type' => 'wpupg_dynamic', | |
| 59 | + 'taxonomy' => $taxonomy, | |
| 60 | + 'values' => explode( ';', str_replace( ',', ';', $terms ) ), | |
| 62 | 61 | 'type' => 'restrict', |
| 63 | 62 | ); |
| 64 | - unset( $options['post_id'] ); | |
| 65 | 63 | } |
| 66 | - | |
| 67 | - if( isset( $options['exclude_post_id'] ) ) { | |
| 68 | - $post_ids = str_replace( ',', ';', $options['exclude_post_id'] ); | |
| 69 | - $post_ids = str_replace( 'current_post', get_the_ID(), $post_ids ); | |
| 70 | - | |
| 71 | - $dynamic_rules[] = array( | |
| 72 | - 'post_type' => 'wpupg_general', | |
| 73 | - 'taxonomy' => 'id', | |
| 74 | - 'values' => explode( ';', $post_ids ), | |
| 75 | - 'type' => 'exclude', | |
| 76 | - ); | |
| 77 | - unset( $options['exclude_post_id'] ); | |
| 78 | - } | |
| 79 | - | |
| 80 | - foreach( $options as $taxonomy => $terms ) { | |
| 81 | - if( taxonomy_exists( $taxonomy ) ) { | |
| 82 | - $dynamic_rules[] = array( | |
| 83 | - 'post_type' => 'wpupg_dynamic', | |
| 84 | - 'taxonomy' => $taxonomy, | |
| 85 | - 'values' => explode( ';', str_replace( ',', ';', $terms ) ), | |
| 86 | - 'type' => 'restrict', | |
| 87 | - ); | |
| 88 | - } | |
| 89 | - } | |
| 90 | 64 | } |
| 91 | 65 | } |
| 92 | - if( count( $dynamic_rules ) > 0 || 'rand' === $grid->order_by() ) { | |
| 66 | + if( count( $dynamic_rules ) > 0 ) { | |
| 93 | 67 | $grid->set_dynamic_rules( $dynamic_rules ); |
| 94 | - } else { | |
| 95 | - // Make sure latest version of grid is shown. | |
| 96 | - $grid_ids = get_option( 'wpupg_regenerate_grids_check', false ); | |
| 97 | - | |
| 98 | - if( $grid_ids && in_array( $grid->ID(), $grid_ids ) ) { | |
| 99 | - WPUltimatePostGrid::get()->helper( 'grid_cache' )->generate( $grid->ID() ); | |
| 100 | - | |
| 101 | - unset( $grid_ids[ array_search( $grid->ID(), $grid_ids ) ] ); | |
| 102 | - update_option( 'wpupg_regenerate_grids_check', $grid_ids ); | |
| 103 | - } | |
| 104 | 68 | } |
| 105 | 69 | |
| 106 | 70 | $link_type = $grid->link_type(); |
| 107 | 71 | $link_target = $grid->link_target(); |