| @@ -25,106 +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 | - if( isset( $options['author'] ) ) { | |
| 81 | - $author_ids = str_replace( ',', ';', $options['author'] ); | |
| 82 | - $author_ids = str_replace( 'current_user', get_current_user_id(), $author_ids ); | |
| 83 | - | |
| 84 | - $dynamic_rules[] = array( | |
| 85 | - 'post_type' => 'wpupg_general', | |
| 86 | - 'taxonomy' => 'author', | |
| 87 | - 'values' => explode( ';', $author_ids ), | |
| 88 | - 'type' => 'restrict', | |
| 89 | - ); | |
| 90 | - unset( $options['author'] ); | |
| 91 | - } | |
| 92 | - | |
| 93 | - if( isset( $options['exclude_author'] ) ) { | |
| 94 | - $author_ids = str_replace( ',', ';', $options['exclude_author'] ); | |
| 95 | - $author_ids = str_replace( 'current_user', get_current_user_id(), $author_ids ); | |
| 96 | - | |
| 97 | - $dynamic_rules[] = array( | |
| 98 | - 'post_type' => 'wpupg_general', | |
| 99 | - 'taxonomy' => 'author', | |
| 100 | - 'values' => explode( ';', $author_ids ), | |
| 101 | - 'type' => 'exclude', | |
| 102 | - ); | |
| 103 | - unset( $options['exclude_author'] ); | |
| 104 | - } | |
| 105 | - | |
| 106 | - foreach( $options as $taxonomy => $terms ) { | |
| 107 | - if( taxonomy_exists( $taxonomy ) ) { | |
| 108 | - $dynamic_rules[] = array( | |
| 109 | - 'post_type' => 'wpupg_dynamic', | |
| 110 | - 'taxonomy' => $taxonomy, | |
| 111 | - 'values' => explode( ';', str_replace( ',', ';', $terms ) ), | |
| 112 | - 'type' => 'restrict', | |
| 113 | - ); | |
| 114 | - } | |
| 115 | - } | |
| 116 | 64 | } |
| 117 | 65 | } |
| 118 | - if( count( $dynamic_rules ) > 0 || 'rand' === $grid->order_by() ) { | |
| 66 | + if( count( $dynamic_rules ) > 0 ) { | |
| 119 | 67 | $grid->set_dynamic_rules( $dynamic_rules ); |
| 120 | - } else if ( WPUltimatePostGrid::option( 'cache_reset_front_end', '1' ) == '1' ) { | |
| 121 | - // Make sure latest version of grid is shown. | |
| 122 | - $grid_ids = get_option( 'wpupg_regenerate_grids_check', false ); | |
| 123 | - | |
| 124 | - if( $grid_ids && in_array( $grid->ID(), $grid_ids ) ) { | |
| 125 | - WPUltimatePostGrid::get()->helper( 'grid_cache' )->generate( $grid->ID() ); | |
| 126 | - } | |
| 127 | 68 | } |
| 128 | 69 | |
| 129 | 70 | $link_type = $grid->link_type(); |
| 130 | 71 | $link_target = $grid->link_target(); |