Hi,
Page showing the issue :
I got your help to put the list of all Main category on this page : hidden link (ticket : https://toolset.com/forums/topic/showing-a-clickable-list-of-child-taxonomy-on-a-taxonomy-view-page/).
Now I try to get something more complete. With a mouse over a taxonomy, I want a list of child taxonomy displayed in a Tooltip window. So for now, it's working well, but showing the complete list of categories in the listing-category taxonomy. So I ONLY want the child category of that specific parent category that the mouse is over.
This is the code in my function.php that display this taxonomy list :
add_filter('wpv_filter_taxonomy_query', function($query, $settings, $views_id){
if($views_id == 412 && isset($_GET['wpv-listing-category'])){
$term = get_term_by('slug', $_GET['wpv-listing-category'], 'listing-category'); // here replace "listing-category" with your custom taxonomy slug
if($term){
unset($query['child_of']);
$query['parent'] = $term->term_id;
}
}
return $query;
}, 99, 3);
add_shortcode('get_term_by_url_param', function($atts){
$res= '';
$atts = shortcode_atts( array(
'url_param' => 'wpv-listing-category',
'tax' => 'listing-category',
), $atts);
if(isset($_GET[$atts['url_param']]) && $_GET[$atts['url_param']] != ''){
$term = get_term_by('slug',$_GET[$atts['url_param']], $atts['tax']);
if($term){
$res = '<strong>Category :</strong> '. $term->name;
}
}
return $res;
});
This is the code for the Loop item in Listing category list
{tooltip}<a href="?wpv-listing-category=[wpv-taxonomy-slug]">[wpv-taxonomy-title]</a>{end-text}[xyz-ips snippet="childcat"]{end-tooltip}
So the Tooltip shortcode is from a plugin that allow me to publish tooltip.
So everything displayed in the tooltip is included in : [xyz-ips snippet="childcat"]
This is the code that I have in this PHP snippet :
<?php
// List terms in a given taxonomy using wp_list_categories (also useful as a widget if using a PHP Code plugin)
$toolsetslug = do_shortcode('[wpv-taxonomy-slug]');
$category = get_category_by_slug($toolsetslug);
$taxonomy = 'listing-category';
$orderby = 'name';
$show_count = false;
$pad_counts = false;
$hierarchical = true;
$title = '';
$args = array(
'taxonomy' => $taxonomy,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'title_li' => $title,
'child_of ' => $category->term_id,
'hide_empty' => 0
);
?>
<ul>
<?php wp_list_categories( $args ); ?>
</ul>
So wp_list_categories publish the full category list. So I need to specify the 'child_of' to make sure that I get the subcategories of the category my mouse is over. To get this category ID, I have created $toolsetslug with do_shortcode to be able to use [wpv-taxonomy-slug] shortcode. $category is there to get the ID from that slug. I didn't find an easier way to get the category ID.
I'm maybe wrong in my code. I'm very newbie and I got pieces of code in different forums. But I still have a feeling that I'm not too far to get what I'm looking for.
Any idea what I could change in this code to get it working?
Thank you very much!