Skip Navigation

[Resolved] How do I limit my dropdown to show only first level in a taxonomy

This support ticket is created 5 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

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 2 replies, has 2 voices.

Last updated by Minesh 5 years, 2 months ago.

Assisted by: Minesh.

Author
Posts
#1342451

I am trying to: Show only the HOA Categories, not the subcategories below each. (example: Carpet Cleaning, not "-best carpet cleaning chemicals")

Link to a page where the issue can be seen: hidden link

I expected to see: Just top level categories for the taxonomy, HOA Categories

Instead, I got: All categories, parent and child.

#1342539

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Actually, there is no native way to filter the taxonomy filter results but I will try to share workaround that will help you to display only top-level terms.

I checked the wp-admin access details you shared and at this end its not working. Can you please share working access details.

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

#1343133
#1343875

Minesh
Supporter

Languages: English (English )

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

Can you please check now: hidden link

I've added the following code to your current theme's functions.php file:

function func_display_only_parent_terms( $query ){
    global $post;
     
    if ( $post->ID == 784 && $query->query_vars['taxonomy'][0] == 'home-service-category' && !is_admin() ) {
        
		$query->query_vars['parent'] = 0;
        
    }
}
add_action( 'pre_get_terms', 'func_display_only_parent_terms',10,1);

Where:
- 784 is the page ID where you are displaying your view.