As I Solve

Bulletproof solutions for the savvy developer.

WordPress Import Posts – Assign to Existing Author


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”

  1. 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);
    });

Leave a Reply