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?
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
I added the code to JS editor in the form but nothing changed. Am I adding the code in the right place?
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;
}
My issue is resolved now. Thank you!