/** * This function deletes transient of certain grids where the Post is included in * @since: 1.2.0 */ public static function check_for_transient_deletion($post_id) { $base = new Essential_Grid_Base(); $categories = $base->get_custom_taxonomies_by_post_id($post_id); $tags = get_the_tags($post_id); $lang = array(); if (Essential_Grid_Wpml::is_wpml_exists()) { $lang = icl_get_languages(); } $cat = array(); if (!empty($categories) || !empty($tags)) { if (!empty($categories)) { foreach ($categories as $c) { $cat[$c->taxonomy][$c->term_id] = true; } } if (!empty($tags)) { foreach ($categories as $c) { $cat[$c->taxonomy][$c->term_id] = true; } } //get all grids, then check all grids $grids = Essential_Grid::get_essential_grids(); if (!empty($grids)) { foreach ($grids as $grid) { $selected = json_decode($grid->postparams, true); $post_category = $base->getVar($selected, 'post_category'); $cat_tax = $base->getCatAndTaxData($post_category); $cats = array(); if (!empty($cat_tax['cats'])) { $cats = explode(',', $cat_tax['cats']); } $taxes = array('post_tag'); if (!empty($cat_tax['tax'])) { $taxes = explode(',', $cat_tax['tax']); } $cont = false; if (!empty($cats)) { foreach ($taxes as $tax) { foreach ($cats as $c) { if (isset($cat[$tax][$c])) { //if set, cache of grid needs to be killed if (!empty($lang)) { foreach ($lang as $code => $val) { delete_transient('ess_grid_trans_query_' . $grid->id . $val['language_code']); delete_transient('ess_grid_trans_full_grid_' . $grid->id . $val['language_code']); } } else { delete_transient('ess_grid_trans_query_' . $grid->id); delete_transient('ess_grid_trans_full_grid_' . $grid->id); } $cont = true; } if ($cont == true) { break; } } if ($cont == true) { break; } } } } } } }
/** * Output Filter from post based * @since 1.0.6 */ public function output_filter_by_posts() { $base = new Essential_Grid_Base(); $nav = new Essential_Grid_Navigation(); $filter_allow = $base->getVar($this->grid_params, 'filter-arrows', 'single'); $filter_start = $grid->getVar($this->grid_params, 'filter-start', ''); $filter_all_text = $base->getVar($this->grid_params, 'filter-all-text', __('Filter - All', EG_TEXTDOMAIN)); $filter_dropdown_text = $base->getVar($this->grid_params, 'filter-dropdown-text', __('Filter Categories', EG_TEXTDOMAIN)); $show_count = $base->getVar($this->grid_params, 'filter-counter', 'off'); $nav->set_filter_text($filter_all_text); $nav->set_dropdown_text($filter_dropdown_text); $nav->set_show_count($show_count); $start_sortby = $base->getVar($this->grid_params, 'sorting-order-by-start', 'none'); $start_sortby_type = $base->getVar($this->grid_params, 'sorting-order-type', 'ASC'); $post_category = $base->getVar($this->grid_postparams, 'post_category'); $post_types = $base->getVar($this->grid_postparams, 'post_types'); $page_ids = explode(',', $base->getVar($this->grid_postparams, 'selected_pages', '-1')); $cat_relation = $base->getVar($this->grid_postparams, 'category-relation', 'OR'); $additional_query = $base->getVar($this->grid_postparams, 'additional-query', ''); if ($additional_query !== '') { $additional_query = wp_parse_args($additional_query); } $cat_tax = Essential_Grid_Base::getCatAndTaxData($post_category); $posts = Essential_Grid_Base::getPostsByCategory($this->grid_id, $cat_tax['cats'], $post_types, $cat_tax['tax'], $page_ids, $start_sortby, $start_sortby_type, -1, $additional_query, true, $cat_relation); $nav_filters = array(); $taxes = array('post_tag'); if (!empty($cat_tax['tax'])) { $taxes = explode(',', $cat_tax['tax']); } if (!empty($cat_tax['cats'])) { $cats = explode(',', $cat_tax['cats']); foreach ($cats as $key => $id) { $cat = get_category($id); if (is_object($cat)) { $nav_filters[$id] = array('name' => $cat->cat_name, 'slug' => sanitize_key($cat->slug)); } foreach ($taxes as $custom_tax) { $term = get_term_by('id', $id, $custom_tax); if (is_object($term)) { $nav_filters[$id] = array('name' => $term->name, 'slug' => sanitize_key($term->slug)); } } } asort($nav_filters); } $found_filter = array(); if (!empty($posts) && count($posts) > 0) { foreach ($posts as $key => $post) { //check if post should be visible or if its invisible on current grid settings $is_visible = $this->check_if_visible($post['ID'], $this->grid_id); if ($is_visible == false) { continue; } // continue if invisible $filters = array(); //$categories = get_the_category($post['ID']); $categories = $base->get_custom_taxonomies_by_post_id($post['ID']); //$tags = wp_get_post_terms($post['ID']); $tags = get_the_tags($post['ID']); if (!empty($categories)) { foreach ($categories as $key => $category) { $filters[$category->term_id] = array('name' => $category->name, 'slug' => sanitize_key($category->slug)); } } if (!empty($tags)) { foreach ($tags as $key => $taxonomie) { $filters[$taxonomie->term_id] = array('name' => $taxonomie->name, 'slug' => sanitize_key($taxonomie->slug)); } } $found_filter = $found_filter + $filters; //these are the found filters, only show filter that the posts have } } $remove_filter = array_diff_key($nav_filters, $found_filter); //check if we have filter that no post has (comes through multilanguage) if (!empty($remove_filter)) { foreach ($remove_filter as $key => $rem) { //we have, so remove them from the filter list before setting the filter list unset($nav_filters[$key]); } } $nav->set_filter($nav_filters); //set filters $nav_filters $found_filter $nav->set_filter_type($filter_allow); $nav->set_filter_start_select($filter_start); $nav->output_filter(); }