When importing posts, pages, or custom posts from an existing WordPress installation, it asks you whether you want to import a user, assign to a new user, or assign to an existing user.
If you have already imported users, you want to assign all posts to existing users. However, if you have a lot of users, it can be a real pain. In my case, I had 7 imports and over 50 users per import to assign to.
Here’s a script that you can run in your inspector console to instantly fill all select options to the correct user.
First, include jQuery.
Then, run the following script:
It grabs the name from the bolded text above each select, finds the option with that text, and makes it selected.
6 responses to “WordPress Import Posts – Assign to Existing Author”
I had to comment to say thank so much for this – you have no idea how much time you just saved me 🙂 great stuff!
Glad to help!
I know I was a bit horrified that I would have to do all that manually..
Thank you Stephen. You saved me from a loooong and boring day of work.
much thanks!
I’ve spent a month moving from a custom CMS w 20k+ authors and 100k+ articles, and this saved me SO much times. Huuuuuuge thanks!!
Thank you so much! Nearly 8 years later this still works with a few minor tweaks. There’s no need to include jQuery as WP does that already, and the option text now includes the username so we don’t need to remove that from the name:
jQuery(‘#authors > li’).each(function(){
var textstring = jQuery(this).find(‘strong’).text();
jQuery(this).find(‘select[name^=user_map] option’).filter(function() {
return jQuery(this).text() == textstring;
}).prop(‘selected’, true);
});