Skip to content

Instantly share code, notes, and snippets.

@tripflex
Last active March 5, 2021 17:56
Show Gist options
  • Save tripflex/4d34701af7f550dbf9c390dc61109163 to your computer and use it in GitHub Desktop.
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
<?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>";
}
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' );
});
@tripflex
Copy link
Author

Combine this together with this code that sets parent taxonomies automatically:
https://gist.github.com/tripflex/65dbffc4342cf7077e49d641462b46ad

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment