Simple Taxonomy Chain Menu


Created by shortcodetaxonomy_chain_menu post_type=’car’ taxonomy=’locations’ show_count=1 button_title=’Watch It’ target=’_blank’ label_taxonomy=’Country|City|District’ label_post=’Select car’

Attention:

  • target=’_blank’ – this attribute is from premium version of the plugin
  • label_taxonomy=’Country|City|District’ – such syntax is from premium version of the plugin

The same shortcode with premium attribute ‘select_wrapper‘:

[taxonomy_chain_menu post_type=’car’ taxonomy=’locations’ show_count=1 button_title=’Watch It’ target=’_blank’ label_taxonomy=’Country|City|District’ label_post=’Select car’ select_wrapper=’selectron23′ chain_id=’chain1′ select_width=’300px|250px’ selectron23_max_open_height=’300′]


The code applied in file functions.php:

add_filter('taxonomy-chain-menu-option-data', function($id, $taxonomy, $parent_id, $chain_id) {
    $data = [];

    $get_thumbnail = function ($thumbnail_id, $size = 'thumbnail') {
        $img = wp_get_attachment_image_src($thumbnail_id, $size);
        if (!isset($img[0])) {
            $img = wp_get_attachment_url($thumbnail_id);
        } else {
            $img = $img[0];
        }

        return $img;
    };

    //+++
    if ($chain_id === 'chain1') {
        if ($taxonomy === 'locations') {
            $term_id = $id;
            if ($term_id > 0) {
                $data['text'] = strip_tags(tag_description($term_id));
                $thumbnail_id = get_term_meta($term_id, 'image', true);
                $data['img'] = $get_thumbnail($thumbnail_id);
            } else {
                //labels
                $deep = 0;
                if ($parent_id > 0) {
                    $deep = count(get_ancestors($parent_id, $taxonomy)) + 1;
                }

                switch ($deep) {
                    case 0:
                        $data['text'] = 'Countries of origin';
                        $data['img'] = $get_thumbnail(491);
                        break;
                    case 1:
                        $data['text'] = 'Cities of origin';
                        $data['img'] = $get_thumbnail(492);
                        break;
                    case 2:
                        $data['text'] = 'Districts of origin';
                        $data['img'] = $get_thumbnail(493);
                        break;
                }
            }
        }

        if ($taxonomy === 'is_post') {
            $post_id = $id;
            $data['text'] = 'Any short text about post here';
            if ($post_id > 0) {
                $data['img'] = $get_thumbnail(get_post_thumbnail_id($post_id)); //featured image
            } else {
                $data['img'] = $get_thumbnail(521); //featured image
            }
        }
    }
    return $data;
}, 10, 4);


Documentation

Buy it separately on: pluginus.net OR Use free version: wordpress.org