Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save theblanchard/de1702d6a16807d6ab48bfbdfe731044 to your computer and use it in GitHub Desktop.
Save theblanchard/de1702d6a16807d6ab48bfbdfe731044 to your computer and use it in GitHub Desktop.
Auto-select authors for posts during WordPress import. They must already be assigned to the project. Enable jQuery in a plugin or functions.php, and paste this in the browser console.
(function($){
$('#authors li').each(function(key, value) {
var name = $(this).children('strong').first().html();
var re = /\s\([^\)]+\)/gi;
name = name.replace(re, '');
name = name.replace(':', '');
name = name.replace("'", "");
name = name.replace(".", "");
name = name.replace("&", "");
$(this).find('select').first().children('option').each(function(){
if (-1 !== $(this).html().indexOf(`(${name})`)) {
console.log('Comparing ' + $(this).html() + ' to ' + name + ".\n");
$(this).attr('selected', 'selected');
}
});
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment