Avoid a tedious author matching process with this handy JS snippet!

Anyone that’s migrated posts from one WordPress site to another has undoubtedly reached a screen that looks something like this:

And then thought, “Do I really need to go through and select each of these authors?!” Unfortunately, the answer is, “Yes.”

Why WordPress has yet to build in a way to automatically select these authors, who knows, but thanks to a contributor at GitHub (https://gist.github.com/webercoder/2870698) we have a way to quickly bypass this pain point!

1. Make Sure Your Authors’ Usernames and Display Names Match

The script works by matching the name displayed after “Import author:” with the name displayed in the dropdown list. Since both of these are formatted as “<Display Name> (<Username>)”, you will have to make sure both the username and display names of your authors are identical. Whether you do this on the site you’re importing from or the site you’re importing to is up to you. And remember, if the user doesn’t exist on the new site, no worries, the import will create the new user automatically.

2. Run the Auto-Select Script in Your Browser’s Console

Here comes the fun part! Open your browser’s console (typically F12 and clicking into the Console tab will do the trick) and run the following code:

(function($){
	$('#authors li').each(function(key, value) {
		var name = $(this).children('strong').first().text();
		$(this).find('select').first().children('option').each(function(){
			var optname = $(this).text();
			if (optname == name) {
				console.log('Comparing ' + optname + ' to ' + name + ".\n");
				$(this).attr('selected', 'selected');
			}
		});
	});
})(jQuery);

If everything runs as expected, you should be all matched up now!

Let us know if you run into any issues in the comments below!

Allen Robinson

Director of Application Development
Allen has been responsible for overseeing client website development, implementation, and maintenance at Foxtrot Media for over 10 years. A Computer Science graduate from the University of Wisconsin- Madison, Robinson is a software development and content management system specialist, fluent in CSS, PHP, MySQL, HTML, and JavaScript.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Allen Robinson

Director of Application Development
Allen has been responsible for overseeing client website development, implementation, and maintenance at Foxtrot Media for over 10 years. A Computer Science graduate from the University of Wisconsin- Madison, Robinson is a software development and content management system specialist, fluent in CSS, PHP, MySQL, HTML, and JavaScript.

Post Details

Software/Plugins:

Languages: