Last active
March 5, 2021 17:56
-
-
Save tripflex/4d34701af7f550dbf9c390dc61109163 to your computer and use it in GitHub Desktop.
Disable parent categories from being selected in taxonomy chosen dropdown for WP Job Manager Field Editor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// ^ there should ONLY be one of these at the top of child theme's functions.php file or use the Code Snippets plugin | |
// THIS IS JUST ANOTHER EXAMPLE USING THE CODE BELOW TO ONLY LOAD ON THE SUBMIT/EDIT LISTING PAGE IF YOU DONT KNOW | |
// HOW TO ADD YOUR OWN CUSTOM JAVASCRIPT | |
add_action( 'submit_job_form_start', 'my_custom_jquery_disable_parent_categories' ); | |
function my_custom_jquery_disable_parent_categories(){ | |
echo "<script> | |
jQuery( function($){ | |
// To use for field other than job_region, change job_region to the meta | |
// key of the field, right below here | |
$( '#job_region > .level-0' ).each( function ( index ) { | |
$( this ).prop( 'disabled', 'disabled' ); | |
}); | |
// and right below here | |
$( '#job_region' ).trigger( 'chosen:updated' ); | |
}); | |
</script>"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery( function($){ | |
// To use for field other than job_region, change job_region to the meta | |
// key of the field | |
$( '#job_region > .level-0' ).each( function ( index ) { | |
$( this ).prop( 'disabled', 'disabled' ); | |
}); | |
$( '#job_region' ).trigger( 'chosen:updated' ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Combine this together with this code that sets parent taxonomies automatically:
https://gist.github.com/tripflex/65dbffc4342cf7077e49d641462b46ad