Пример #1
0
 public function avh_wp_group_category_checklist($selected_cats, $number)
 {
     $walker = new AVH_Walker_Category_Checklist();
     $walker->number = $number;
     $walker->input_id = $this->get_field_id('post_group_category');
     $walker->input_name = $this->get_field_name('post_group_category');
     $walker->li_id = $this->get_field_id('group_category--1');
     $args = array('taxonomy' => 'avhec_catgroup', 'descendants_and_self' => 0, 'selected_cats' => array(), 'popular_cats' => array(), 'walker' => $walker, 'checked_ontop' => true);
     if (is_array($selected_cats)) {
         $args['selected_cats'] = $selected_cats;
     } else {
         $args['selected_cats'] = array();
     }
     $categories = (array) get_terms($args['taxonomy'], array('get' => 'all'));
     // Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache)
     $checked_categories = array();
     $keys = array_keys($categories);
     foreach ($keys as $k) {
         if (in_array($categories[$k]->term_id, $args['selected_cats'])) {
             $checked_categories[] = $categories[$k];
             unset($categories[$k]);
         }
     }
     // Put checked cats on top
     echo $walker->walk($checked_categories, 0, $args);
     // Then the rest of them
     echo $walker->walk($categories, 0, $args);
 }
 /**
  * Creates the categories checklist
  *
  * @param int   $post_id
  * @param int   $descendants_and_self
  * @param array $selected_cats
  * @param array $popular_cats
  * @param int   $number
  */
 function avh_wp_category_checklist($selected_cats, $number)
 {
     $walker = new AVH_Walker_Category_Checklist();
     $walker->number = $number;
     $walker->input_id = $this->get_field_id('post_category');
     $walker->input_name = $this->get_field_name('post_category');
     $walker->li_id = $this->get_field_id('category--1');
     $args = array('taxonomy' => 'category', 'descendants_and_self' => 0, 'selected_cats' => $selected_cats, 'popular_cats' => array(), 'walker' => $walker, 'checked_ontop' => true, 'popular_cats' => array());
     if (is_array($selected_cats)) {
         $args['selected_cats'] = $selected_cats;
     } else {
         $args['selected_cats'] = array();
     }
     $categories = $this->core->getCategories();
     $_categories_id = $this->core->getCategoriesId($categories);
     // Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache)
     $checked_categories = array();
     foreach ($args['selected_cats'] as $key => $value) {
         if (isset($_categories_id[$key])) {
             $category_key = $_categories_id[$key];
             $checked_categories[] = $categories[$category_key];
             unset($categories[$category_key]);
         }
     }
     // Put checked cats on top
     echo $walker->walk($checked_categories, 0, array($args));
     // Then the rest of them
     echo $walker->walk($categories, 0, array($args));
 }