start_controls_section( 'section_title', [ 'label' => __( 'Category', 'administrator-z' ), ] ); $post_types = get_post_types( ['public'=>true], 'objects' ); $arr_post_types = array(); foreach ($post_types as $key => $post_type) { $arr_post_types[$post_type->name] = $post_type->labels->singular_name; } $this->add_control( 'post_type', [ 'label' => __( 'Select Post Type', 'administrator-z' ), 'type' => \Elementor\Controls_Manager::SELECT, 'options' => $arr_post_types, 'default' => $this->get_default($arr_post_types,'post'), ] ); foreach ($post_types as $key => $post_type) { $taxonomy_objects = get_object_taxonomies( $post_type->name, 'objects' ); $arr_taxonomy = array(); if(!empty($taxonomy_objects)){ foreach ($taxonomy_objects as $taxonomy) { $arr_taxonomy[$taxonomy->name] = $taxonomy->label; } } $this->add_control( 'taxonomy_'.$post_type->name, [ 'label' => __( 'Filter by category', 'administrator-z' ), 'type' => \Elementor\Controls_Manager::SELECT, 'options' => $arr_taxonomy, 'default' => $this->get_default($arr_taxonomy,''), 'condition'=> ['post_type'=>$post_type->name], ] ); } $this->add_control( 'title_size', [ 'label' => __( 'Title HTML Tag', 'administrator-z' ), 'type' => \Elementor\Controls_Manager::SELECT, 'options' => [ 'h1' => 'H1', 'h2' => 'H2', 'h3' => 'H3', 'h4' => 'H4', 'h5' => 'H5', 'h6' => 'H6', 'div' => 'div', 'span' => 'span', 'p' => 'p', ], 'default' => 'h3', 'separator' => 'before', ] ); $this->add_control( 'title_text', [ 'label'=> __( 'Title', 'administrator-z' ), 'type' => \Elementor\Controls_Manager::TEXT, 'default' => '', 'placeholder' => __( 'Empty', 'administrator-z' ), ] ); $this->add_control( 'toggled', [ 'label' => __( 'Toggled items', 'plugin-domain' ), 'type' => \Elementor\Controls_Manager::SWITCHER, 'label_on' => __( 'Yes', 'your-plugin' ), 'label_off' => __( 'No', 'your-plugin' ), 'return_value' => 'yes', 'default' => 'no', ] ); $this->end_controls_section(); } private function get_default($arr,$default){ if(empty($arr)){ return $default; }else { foreach ($arr as $key => $value) { return $key; } } return ; } protected function render() { $settings = $this->get_settings_for_display(); $title_text = $settings['title_text']; $taxonomy = $settings['taxonomy_'.$settings['post_type']]; $rand = 'adminz_cat'.wp_rand(); $html = '
'; ?> $cat) { if ($cat->parent == $parentId) { unset($cat->filter); unset($cat->term_group); unset($cat->description); $cat->ancestors = count(get_ancestors( $cat->term_id, $cat->category,"taxonomy")); //unset($cat->taxonomy); $into[$cat->term_id] = $cat; unset($cats[$i]); } } foreach ($into as $topCat) { $topCat->children = array(); $this->sort_terms_hierarchically($cats, $topCat->children, $topCat->term_id); } } function call_children_html($categoryHierarchy){ $settings = $this->get_settings_for_display(); $active = $settings['toggled'] =="yes" ? "active" : ""; $cssdisplay = $settings['toggled'] =="yes" ? "display: block;" : ""; if(!is_array($categoryHierarchy)) return; if(empty($categoryHierarchy)) return; ob_start(); foreach ($categoryHierarchy as $key=> $cat) { if (!empty($cat->children)) { ?>