Home › Forums › Backend Issues (wp-admin) › Add Term ID as class to checkbox › Reply To: Add Term ID as class to checkbox
Been playing around and so far this is my code that works, it gets the value of the checkbox but only on the selected/saved one. The code below gives me “southern 360” where 360 is the value of the saved/selected checkbox and southern is the correct region if based on the 360 ID. This is the same on all checkbox divs though and what I need is for each checkbox div to show the ID value of its respective checkbox.
How can I change it so that it will add the value of the checkbox per checkbox and not the selected one?
function filter_region_taxonomy() { ?>
<script type="text/javascript">
(function($) {
// Document Ready
$(document).ready(function() {
$('#acf-standard_region select').trigger('change');
});
$('#acf-standard_region .acf-taxonomy-field select').live('change', function() {
var value = $(this).val();
$( "#acf-standard_company:checkbox" ).addClass("compclass");
if( value == "7" ) {
$( "#acf-standard_company ul.acf-checkbox-list li ul.children li" ).removeClass( "southern no-class" ).addClass(("<?php $terms = get_the_terms( get_the_ID(), 'company'); if( !empty($terms) ) { $term = array_pop($terms); $term_id = $term->term_id; $regionVal = get_field('jobsite_region', 'company_' . $term_id ); echo $regionVal . ' ' . $term_id; } ?>");
$('#acf-standard_company').show();
$('ul.acf-checkbox-list li').show();
}
else if( value == "9" ) {
$( "#acf-standard_company ul.acf-checkbox-list li ul.children li" ).removeClass( "northern no-class" ).addClass(("<?php $terms = get_the_terms( get_the_ID(), 'company'); if( !empty($terms) ) { $term = array_pop($terms); $term_id = $term->term_id; $regionVal = get_field('jobsite_region', 'company_' . $term_id ); echo $regionVal . ' ' . $term_id; } ?>");
$('#acf-standard_company').show();
$('ul.acf-checkbox-list li').show();
}
else {
$( "#acf-standard_company ul.acf-checkbox-list li ul.children li" ).removeClass( "southern northern" ).addClass( "no-class" );
$('#acf-standard_company').hide();
$('ul.acf-checkbox-list li').hide();
}
});
})(jQuery);
</script>
<?php }
add_action('acf/input/admin_head', 'filter_region_taxonomy');
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
Are you building WordPress sites with ACF and @BeaverBuilder, and wanted to use your ACF Blocks in both the block editor and Beaver Builder?
— Advanced Custom Fields (@wp_acf) May 10, 2023
The BB team recently added support for using ACF Blocks in Beaver Builder. Check it out 👇https://t.co/UalEIa5aQi
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.