Skip Navigation

[Resolved] Show only child taxonomy terms in the dropdown

This support ticket is created 3 years, 4 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

This topic contains 4 replies, has 2 voices.

Last updated by himanshuS 3 years, 4 months ago.

Assisted by: Waqar.

Author
Posts
#1869379

Tell us what you are trying to do?
I have parent skills category and then child categories as actual skills. I only want to show child terms in the dropdown on submit form.

Is there any documentation that you are following?
I am using the following doc to write code: https://toolset.com/forums/topic/how-do-i-limit-my-dropdown-to-show-only-first-level-in-a-taxonomy/#post-1343875

I have a snippet with the following code to test if only parent terms are shown but it doesn't work:
function display_only_parent_terms( $query ){
global $post;

if ( $post->ID == 5856 && $query->query_vars['taxonomy'][0] == 'skill-category') {

$query->query_vars['parent'] = 0;

}
}
add_action( 'pre_get_terms', 'display_only_parent_terms',10,1);

What am I missing? Can someone please help?

#1869843

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting us and I'd be happy to assist.

I couldn't make the code snippet from the other thread work on my test website either, so it seems something must have changed since it was written.

If you'd like to hide only the parent terms from the view's dropdown type search filter for a taxonomy, you can use a custom script, for example:


jQuery(document).ready(function() {
	jQuery('select[name="wpv-category"] option').each(function() {
		var str = this.text;
		if (!(str.match("^  -"))) {
			jQuery(this).hide();
		}
	});
});

Note: Please replace "wpv-category" with the actual name of the taxonomy select field used in your view.

regards,
Waqar

#1870459
child terms.png

I added the code to JS editor in the form but nothing changed. Am I adding the code in the right place?

#1872763

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for writing back.

The other thread that you referred to was about the category terms in the search form for the view, that is why I thought you meant the same.

For a regular post form, you can add the following CSS code in the "CSS editor" and it will hide the parent terms:


select[name="skill-category[]"] option[data-parent="-1"] {
display: none;
}

#1873573

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.