Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to import WordPress User First, Last, Description to BP with MySQL

  • @neosnc

    Participant

    After searching for a plugin to import WordPress user data into BuddyPress, I ran across this helpful but dated article on the topic: http://aendrew.com/content/importing-proprietary-user-database-buddypress-boss/

    Using that as a guide I wrote 3 MySQL queries to import First Name, Last Name and Description from standard WordPress user meta data. I also added empty string checks and an if exists check to prevent duplicate data. Always make a backup first and use as needed.


    /* first name import */
    INSERT INTO wp_bp_xprofile_data (field_id, user_id, value, last_updated)
    SELECT '2' AS field_id, wp_usermeta.user_id AS user_id, wp_usermeta.meta_value AS value, NOW() AS last_updated
    FROM wp_usermeta
    WHERE wp_usermeta.meta_key='first_name'
    AND TRIM( wp_usermeta.meta_value ) != ''
    AND NOT EXISTS (
    SELECT value FROM wp_bp_xprofile_data WHERE field_id='2' AND
    wp_bp_xprofile_data.user_id=wp_usermeta.user_id
    );

    /* last name import */
    INSERT INTO wp_bp_xprofile_data (field_id, user_id, value, last_updated)
    SELECT '3' AS field_id, wp_usermeta.user_id AS user_id, wp_usermeta.meta_value AS value, NOW() AS last_updated
    FROM wp_usermeta
    WHERE wp_usermeta.meta_key='last_name'
    AND TRIM( wp_usermeta.meta_value ) != ''
    AND NOT EXISTS (
    SELECT value FROM wp_bp_xprofile_data WHERE field_id='3' AND
    wp_bp_xprofile_data.user_id=wp_usermeta.user_id
    );

    /* description import */
    INSERT INTO wp_bp_xprofile_data (field_id, user_id, value, last_updated)
    SELECT '12' AS field_id, wp_usermeta.user_id AS user_id, wp_usermeta.meta_value AS value, NOW() AS last_updated
    FROM wp_usermeta
    WHERE wp_usermeta.meta_key='description'
    AND TRIM( wp_usermeta.meta_value ) != ''
    AND NOT EXISTS (
    SELECT value FROM wp_bp_xprofile_data WHERE field_id='12' AND
    wp_bp_xprofile_data.user_id=wp_usermeta.user_id
    );

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to import WordPress User First, Last, Description to BP with MySQL’ is closed to new replies.
Skip to toolbar