Skip to content

Instantly share code, notes, and snippets.

@benmay
Created October 23, 2012 10:04
Show Gist options
  • Save benmay/3937999 to your computer and use it in GitHub Desktop.
Save benmay/3937999 to your computer and use it in GitHub Desktop.
Adds a "select all" and "deselect" all link to a taxonomy or category box while editing a WordPress post. addSelectAlltoTaxGroup($key) where $key = taxonomy name.
jQuery(document).ready(function($) {
addSelectAlltoTaxGroup( 'region' );
addSelectAlltoTaxGroup( 'program' );
function addSelectAlltoTaxGroup( key )
{
var selectAll = "<span class=\"my-selector\">&nbsp; | <a href=\"#"+key+"-adder\" id=\""+key+"-select-all\">Select All</a></span>";
var deselectAll = "<span class=\"my-selector\">&nbsp; | <a href=\"#"+key+"-adder\" id=\""+key+"-deselect-all\">Deselect All</a></span>";
$('#taxonomy-'+key+' #'+key+'-adder h4').append( selectAll );
$('#'+key+'-deselect-all').live( 'click', function() {
$('#'+key+'-all :checkbox').each( function() { $(this).prop('checked', false ); });
$('#taxonomy-'+key+' #'+key+'-adder h4 span.my-selector').remove();
$('#taxonomy-'+key+' #'+key+'-adder h4').append( selectAll );
return false;
})
$('#'+key+'-select-all').live( 'click', function() {
$('#'+key+'-all :checkbox').each( function() { $(this).prop('checked', true ); });
$('#taxonomy-'+key+' #'+key+'-adder h4 span.my-selector').remove();
$('#taxonomy-'+key+' #'+key+'-adder h4').append( deselectAll );
return false;
})
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment