Support has been upgraded!
The Support Forum is closed. Not to worry! Providing the top quality support you expect and we're known for will continue! We're not ending support, just changing where you submit requests. This will provide you with the best experience possible.
Premium Support
Have you purchased an addon for Connections such as one of our premium templates or extensions with a valid license and you need help?
Please open a Support Ticket in your user account.
Free Support
Are you using the free Connections plugin? Don't worry, you are still very important to us! We are still providing you with the same high quality support that we're known for.
Please open a new support topic in the WordPress support forums for Connections.
Tagged: 8.21, csv import, extension
- This topic has 13 replies, 2 voices, and was last updated 8 years ago by
Steven Zahm.
-
AuthorPosts
-
07/06/2018 at 10:24 am #466960
Age de Jong
ParticipantHi,
With the help of this QuickTip I try to import some data.
I created this code snippet:
add_filter( 'cncsv_map_import_fields', 'cncsv_import_meta_fields_options' );
function cncsv_import_meta_fields_options( $fields ) {$fields['member_nobnummer'] = 'Membership | NOB-nummer'; $fields['member_noodcontactpersoon'] = 'Membership | Naam contactpersoon bij nood'; $fields['member_hoogsteduikbrevet'] = 'Membership | Hoogste duikbrevet'; $fields['member_soortlidmaatschap'] = 'Membership | Soort lidmaatschap'; $fields['member_instructeur'] = 'Membership | Instructeur'; $fields['member_instructeursnummer'] = 'Membership | Instructeursnummer'; return $fields;}
add_action( 'cncsv_import_fields', 'cncsv_import_meta_fields_import', 10, 2 );
function cncsv_import_meta_fields_import( $id, $row ) {$nobnummer = isset( $row->member_nobnummer ) ? $row->member_nobnummer : ''; $noodcontactpersoon = isset( $row->member_noodcontactpersoon ) ? $row->member_noodcontactpersoon : ''; $hoogsteduikbrevet = isset( $row->member_hoogsteduikbrevet ) ? $row->member_hoogsteduikbrevet : ''; $soortlidmaatschap = isset( $row->member_soortlidmaatschap ) ? $row->member_soortlidmaatschap : ''; $instructeur = isset( $row->member_instructeur ) ? $row->member_instructeur : ''; $instructeursnummer = isset( $row->member_instructeursnummer ) ? $row->member_instructeursnummer : ''; cnEntry_Action::meta( 'update', $id, array( array( 'key' => 'NOB-Relatienummer', 'value' => $nobnummer ), array( 'key' => 'Naam contactpersoon bij nood', 'value' => $noodcontactpersoon ), array( 'key' => 'Hoogste duikbrevet', 'value' => $hoogsteduikbrevet ), array( 'key' => 'Soort lidmaatschap', 'value' => $soortlidmaatschap ), array( 'key' => 'Instructeur', 'value' => $instructeur ), array( 'key' => 'Instructeursnummer', 'value' => $instructeursnummer ) ) );}
After selecting the csv file I can select the corresponding custom fields, but all are empty after the import.What am I doing wrong?
With kind regards, Age
Attachments:
You must be logged in to view attached files.07/06/2018 at 10:25 am #466962Age de Jong
ParticipantHmm, the code isn’t looking good….
I attached it now.Attachments:
You must be logged in to view attached files.07/06/2018 at 12:06 pm #466974Steven Zahm
Keymaster@ Age
Glancing at the code and everything appears correct. Could you please attach a sample CSV file so I can take a look and give a quick test?
07/09/2018 at 5:21 am #467082Age de Jong
ParticipantThis reply has been marked as private.07/09/2018 at 10:35 am #467105Steven Zahm
Keymaster@ Age
You should see a new update for CSV Import, please update and change the code snippet to this code to make it compatible with 2.0:
add_filter( 'cncsv_map_import_fields', 'cncsv_import_meta_fields_options' ); function cncsv_import_meta_fields_options( $fields ) { $fields['member_nobnummer'] = 'Membership | NOB-nummer'; $fields['member_noodcontactpersoon'] = 'Membership | Naam contactpersoon bij nood'; $fields['member_hoogsteduikbrevet'] = 'Membership | Hoogste duikbrevet'; $fields['member_soortlidmaatschap'] = 'Membership | Soort lidmaatschap'; $fields['member_instructeur'] = 'Membership | Instructeur'; $fields['member_instructeursnummer'] = 'Membership | Instructeursnummer'; return $fields; } add_action( 'cncsv_import_fields', 'cncsv_import_meta_fields_import', 10, 3 ); function cncsv_import_meta_fields_import( $id, $row, $entry ) { $nobnummer = $entry->arrayPull( $row, 'member_nobnummer', '' ); $noodcontactpersoon = $entry->arrayPull( $row, 'member_noodcontactpersoon', '' ); $hoogsteduikbrevet = $entry->arrayPull( $row, 'member_hoogsteduikbrevet', '' ); $soortlidmaatschap = $entry->arrayPull( $row, 'member_soortlidmaatschap', '' ); $instructeur = $entry->arrayPull( $row, 'member_instructeur', '' ); $instructeursnummer = $entry->arrayPull( $row, 'member_instructeursnummer', '' ); $meta = array( array( 'key' => 'NOB-Relatienummer', 'value' => $nobnummer ), array( 'key' => 'Naam contactpersoon bij nood', 'value' => $noodcontactpersoon ), array( 'key' => 'Hoogste duikbrevet', 'value' => $hoogsteduikbrevet ), array( 'key' => 'Soort lidmaatschap', 'value' => $soortlidmaatschap ), array( 'key' => 'Instructeur', 'value' => $instructeur ), array( 'key' => 'Instructeursnummer', 'value' => $instructeursnummer ) ); cnEntry_Action::meta( 'update', $id, $meta ); }Hope this helps, let me know!
07/10/2018 at 7:51 am #467159Age de Jong
ParticipantIt’s working perfectly!
Don’t know if I asked it before but will it be possible in the feature to import data for the extensions? Like Certificates.
Greetings, Age
07/10/2018 at 10:25 am #467167Steven Zahm
Keymaster@ Age
Yes, it is possible. But, I have not worked out the code to do so. I think it would be pretty straightforward…
You would use the
cncsv_map_import_fieldsfilter to add theCertificationsfield mapping choice to the drop down.You would also use the
cncsv_import_fieldsto register the callback to import the Certifications. Much like importing the meta code.The code within the function would be nearly identical to the code in the file
class.cncsv-entry.phpfile in theprocessTerms()method around line518. This file is part of the Connections CSV Import extension.Off the top, the only changes would be changing the taxonomy from
categorytocertificationand theelseifto add the default could be removed since it is not required.Something like this (untested):
add_filter( 'cncsv_map_import_fields', 'cncsv_import_certifications_field_option' ); function cncsv_import_certifications_field_option( $fields ) { $fields['certifications'] = 'Certifications'; return $fields; } add_action( 'cncsv_import_fields', 'cncsv_import_certification_field_import', 10, 3 ); function cncsv_import_certification_field_import( $id, $row, $entry ) { $termIDs = array(); $parsed = $entry->arrayPull( $row, 'certification', $termIDs ); if ( ! empty( $parsed ) ) { /* * Convert the supplied certifications to an array and sanitize. * Apply the same filters added to the core WP default filters for `pre_term_name` so the certification name * will return a match if it exists. */ $certifications = explode( ',', $parsed ); $certifications = array_map( 'sanitize_text_field', $certifications ); $certifications = array_map( 'wp_filter_kses', $certifications ); $certifications = array_map( '_wp_specialchars', $certifications ); foreach ( $certifications as $certification ) { // Query the db for the term to be added. $term = cnTerm::getBy( 'name', $certification, 'certification' ); if ( $term instanceof cnTerm_Object ) { $termIDs[] = $term->term_id; } else { // Add the new certification. $insert_result = cnTerm::insert( $certification, 'certification', array( 'slug' => '', 'parent' => '0', 'description' => '' ) ); if ( ! is_wp_error( $insert_result ) ) { $termIDs[] = $insert_result['term_id']; } } } } // Do not set certification relationships if $termIDs is empty because if updating, it will delete existing relationships. if ( ! empty( $termIDs ) ) Connections_Directory()->term->setTermRelationships( $id, $termIDs, 'certification' ); }-
This reply was modified 8 years, 1 month ago by
Steven Zahm. Reason: Code corrections
07/18/2018 at 4:16 am #467755Age de Jong
ParticipantI will wait until it get’s available within the plugin. Just to scared to try things myself :)
07/18/2018 at 9:22 am #467808Steven Zahm
Keymaster@ Age
You could add this particular code to using the Code Snippets plugin. That way you do not have to edit the plugin directly and if it does not work you can deactivate it.
07/19/2018 at 11:42 am #467922Steven Zahm
Keymaster@ Age
I just release an update to Certifications which add support for importing certifications and attaching them to the entry.
Add a
Certificationscolumn to your CSV file. You can import a single cert or multiple certs per entry/CSV row.For a single cert just add the name, eg.
"Cert One".To import and attach more than one, eg.
"Cert One, Cert Two, Cert Three".Basically just like categories. Hope this makes sense!
-
This reply was modified 8 years, 1 month ago by
-
AuthorPosts
You cannot reply to this support topic. Please open your own support topic.
