Skip Navigation

[Assigned] Output child taxonomy list

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 4 replies, has 1 voice.

Last updated by Thorworx 1 hour ago.

Assisted by: Minesh.

Author
Posts
#2818084

Tell us what you are trying to do? Output posts with conditional taxonomy

Is there any documentation that you are following?
https://toolset.com/forums/topic/use-parents-post-slug-inside-a-conditional-statement/
(Several other documentation pages)

What is the link to your site? hidden link

I need to output a list of SUB-categories that have a taxonomy slug that includes the current CPT's slug.

I have a CPT called "Service Areas".
The (hierarchical!) taxonomy is called "Service Area Categories"

Example:
Environmental <-- Service Area AND Top level Service Area Category
Hazardous Materials <-- Subcategory
Wastewater <-- Subcategory
etc
Transportation <-- Service Area AND Top level Service Area Category
Airport Engineering <-- Subcategory
Bicycle and Pedestrian Facilities <-- Subcategory
etc

On each Service Area page, I want to display a view with ONLY the subcategories (children) that match the current Service Area's subcategories.

The WordPress code for this is:
[code]<?php
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
if ($term->parent == 0) {
$args = array(
'taxonomy' => 'subject',
'depth' => 1,
'show_count' => 0,
'title_li' => '',
'child_of' => $term->term_id
);
wp_list_categories($args);
} else {
$args = array(
'taxonomy' => 'subject',
'depth' => 1,
'show_count' => 0,
'title_li' => '',
'child_of' => $term->parent
);
wp_list_categories($args);
}
?>[/code]
... but I need to convert this to a Toolset view/query, probably by creating a shortcode? Get term slug from current page and output children?

Thanks for any help!

#2818195

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Can you please share example service area page and share details on that service area page what child terms you want to display and what exactly the information you want to display and on what section of the page.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2819466

I replied to this 2 days ago.. is there any update?
Thanks!

#2819476

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've created the following view:
- hidden link

I've added the following code to "Custom code" section offered by Toolset:
=> hidden link

function func_display_subcats( $query_settings, $view_settings, $view_id  ){
 global $wp_query;
 global $post;
    if ( $view_id == 2553){
        
        $term_slug = $post->post_name;
        $taxonomy = 'service-area-categories';
        $parent = get_term_by('slug', $term_slug,$taxonomy);
      
       if ($parent) {
  		  $parent_id = $parent->term_id;
		  $query_settings['child_of'] = $parent_id;
       }
        
    }
    return $query_settings;
}
add_filter( 'wpv_filter_taxonomy_query', 'func_display_subcats', 30, 3 );

More info:
- https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_taxonomy_query

On the content template you mentioned, I've added the "Fields and Text" block and added the above view to it:
=> hidden link

[wpv-view name="show-child-categories"]

Please check now:
- hidden link

Please make sure that the post slug and the taxonomy term slug should be same in order to match the post slug equal to parent taxonomy tern slug.

#2819490

Thanks for your help Minesh...

On the View that you created, you added a taxonomy filter to display the child categories of "Planning", so the view displays only "Planning" subcategories... NOT the child categories of the current page. It looks like you've included the conditional in the "Custom code", so can/should this taxonomy filter be removed?

Also, can the view easily be converted to blocks so that I can format the output?