csv Importer Question
-
Hi,
Is there a way to import the csv with user name and email?
Otherwise all imported is assigned to the admin? Or do i miss something?
Thanks
-
Or if the users are ALREADY created, just to map them with their Listings from the csv?
Hello @dimalifragis
Thank you for reaching out.
It is possible to specify the author for each listing while importing in bulk. For this you need to create a column named “author” and specify the author ID in this column. Use the following code to allow system to import these “author” column –
add_action('directorist_listing_imported', function ($post_id, $post) { // Review & Ratings $author = isset($post['author']) && !empty($post['author']) ? $post['author'] : 0; // Update Post Author if( $author ){ $arg = array( 'ID' => $post_id, 'post_author' => $author, ); wp_update_post($arg); } }, 10, 2);Please inform me if you find trouble implementing this.
Kind Regards
Hi there !!
You mean create an “author” column in the csv? And what is the author ID? From where?
Are we talking about ALDEADY existing users in WordPress?
Thanks
(edit)
Or better see my csv format:
user_name,user_email,title,description,date,category,location,price,address,phone,website,image_1,image_2,image_3,image_4
-
This reply was modified 2 years, 1 month ago by
dimal.
Ok,
Will this also map to the correct user during import?
add_action('directorist_listing_imported', function ($post_id, $post) { // Assuming your CSV has columns: user_login, user_email $email = isset($post['user_email']) ? $post['user_email'] : ''; if (!empty($email)) { $user = get_user_by('email', $email); if ($user) { $arg = array( 'ID' => $post_id, 'post_author' => $user->ID, ); wp_update_post($arg); } // No need for an else block since all users exist } }, 10, 2);Thanks
It will only work for already existed user. You need to provide the user ID in the “author” column.
You are trying to import by user email address. This should work fine as well. Please try the code with one or two sample an check if it works.
Please let me know if you need further assistance.
Regards
It is easier to first import the users & emails from an imported plugin and then use this snippet for the Directorist importer.
I spend all night to test and and works great. I have imported 5000+ listing and around 700 users without a single problem.
Thanks
@mahfuz87 I would like to personally thank you for helping me in my issues.
all the best
-
This reply was modified 2 years, 1 month ago by
The topic ‘csv Importer Question’ is closed to new replies.