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.
- This topic has 15 replies, 2 voices, and was last updated 7 years, 6 months ago by
Steven Zahm.
-
AuthorPosts
-
02/06/2019 at 12:06 pm #483808
CRAIG HALLER
ParticipantI guess I am going to push the limits of that great support … :)
I want to add a code number I have for each school and use that if I can in the Connections_Directory()->retrieve->entries call. I don’t want it typically seen so I thought of putting it in an IM set for unlisted.
I see it in a var_dump of an entry:
[“im”]=> string(165) “a:1:{i:0;a:7:{s:2:”id”;s:8:”12345678″;
s:4:”type”;s:3:”aim”;s:4:”name”;
s:3:”AIM”;s:10:”visibility”;
s:8:”unlisted”;s:5:”order”;i:0;s:9:”preferred”;b:0;s:3:”uid”;i:1;}}”yet
$im = $entry->getIm();
returns
array(0) { }Is there a way I can do this? Other suggestions? Just need that code, 12345678 for example, to be not displayed but used to search for a specific entry. Should I be using a custom field?
Also, how do I access the textbox and checkboxes I added?
Thank you.
02/06/2019 at 12:31 pm #483809Steven Zahm
Keymaster@ Craig
RE: so I thought of putting it in an IM set for unlisted
If the var_dump is on the frontend, unlisted will be filtered out of the results.
RE: Should I be using a custom field?
Yep.
RE: how do I access the textbox and checkboxes I added?
why, use the meta query of course (take this as a light hearted tongue in cheek state expression)
Here’s how you would query a custom text field value (I think, off the top of my head.).
$results = Connections_Directory()->retrieve->entries( array( 'meta_query' => array( 'meta_key' => 'custom text field ID', 'meta_value' => 'code number', ), ) );The
meta_keyneeds to exactly the field ID you used to register the custom text field.The
meta_valueshould be your school ID field.A checkbox would be similar, but
meta_valuewould be1for selected and0for not selected (if I remember correctly).02/06/2019 at 1:19 pm #483813CRAIG HALLER
ParticipantIf I were to be offended by light hearted tongue in cheek (which I easily recognize) I would be in great trouble! Anything short of outright F-bombs is fine! :)
Ok, that seems to be working, the custom meta does it. I am guessing that I need to do a snippet like I did for my other textbox to be able to import the value from a csv file but I don’t have to register it?
Do I just use these two routines?
// Register the custom fields CSV Import mapping options and processing callback. add_filter( 'cncsv_map_import_fields', 'cncsv_header_name' ); add_action( 'cncsv_import_fields', 'cncsv_process_import', 10, 3 ); function cncsv_header_name( $fields ) { // The field_id should match exactly the field id used when registering the custom field. $fields['schl_field_id_1'] = 'Grades'; return $fields; } function cncsv_process_import( $id, $row, $entry ) { // The field_id should match exactly the field id used when registering the custom field. $data = $entry->arrayPull( $row, 'schl_field_id_1', '' ); $data = cnFormatting::maybeJSONdecode( stripslashes( $data ) ); cnEntry_Action::meta( 'update', $id, array( array( 'key' => 'schl_field_id_1', // 'value' => $data ), ) ); }Where do I send the Starbucks card?
02/06/2019 at 2:15 pm #483817Steven Zahm
Keymaster@ Craig
RE: I am guessing that I need to do a snippet like I did for my other textbox to be able to import the value from a csv file but I don’t have to register it? … Do I just use these two routines?
Hmmm… you sort of lost me.
You should register all the custom text fields. And if you want to import them, you need to register them with the CSV Import functions like your snippet above does.
When adding multiple fields you do not need to add additional snippets, just update the existing ones to include all the fields.
Here’s an example which registers three fields and imports them:
// Register the metabox and fields. add_action( 'cn_metabox', 'cn_register_custom_metabox_and_text_field' ); function cn_register_custom_metabox_and_text_field() { $atts = array( 'title' => 'Metabox Name', // Change this to a name which applies to your project. 'id' => 'custom_one', // Change this so it is unique to you project. 'context' => 'normal', 'priority' => 'core', 'fields' => array( array( 'name' => 'Field One', // Change this field name to something which applies to you project. 'show_label' => TRUE, // Whether or not to display the 'name'. Changing it to false will suppress the name. 'id' => 'field_one', // Change this so it is unique to you project. Each field id MUST be unique. 'type' => 'text', // This is the field type being added. 'size' => 'regular', // This can be changed to one of the following: 'small', 'regular', 'large' ), array( 'name' => 'Field Two', // Change this field name to something which applies to you project. 'show_label' => TRUE, // Whether or not to display the 'name'. Changing it to false will suppress the name. 'id' => 'field_two', // Change this so it is unique to you project. Each field id MUST be unique. 'type' => 'text', // This is the field type being added. 'size' => 'regular', // This can be changed to one of the following: 'small', 'regular', 'large' ), array( 'name' => 'Field Three', // Change this field name to something which applies to you project. 'show_label' => TRUE, // Whether or not to display the 'name'. Changing it to false will suppress the name. 'id' => 'field_three', // Change this so it is unique to you project. Each field id MUST be unique. 'type' => 'text', // This is the field type being added. 'size' => 'regular', // This can be changed to one of the following: 'small', 'regular', 'large' ), ), ); cnMetaboxAPI::add( $atts ); } // Register the custom fields CSV Import mapping options and processing callback. add_filter( 'cncsv_map_import_fields', 'cncsv_header_name' ); add_action( 'cncsv_import_fields', 'cncsv_process_import', 10, 3 ); function cncsv_header_name( $fields ) { // The field_id should match exactly the field id used when registering the custom field. $fields['field_one'] = 'Field One'; $fields['field_two'] = 'Field Two'; $fields['field_three'] = 'Field Three'; return $fields; } function cncsv_process_import( $id, $row, $entry ) { // The field_id should match exactly the field id used when registering the custom field. $one = $entry->arrayPull( $row, 'field_one', '' ); $one = cnFormatting::maybeJSONdecode( stripslashes( $one ) ); $two = $entry->arrayPull( $row, 'field_two', '' ); $two = cnFormatting::maybeJSONdecode( stripslashes( $two ) ); $three = $entry->arrayPull( $row, 'field_three', '' ); $three = cnFormatting::maybeJSONdecode( stripslashes( $three ) ); cnEntry_Action::meta( 'update', $id, array( array( 'key' => 'field_one', 'value' => $one ), array( 'key' => 'field_two', 'value' => $two ), array( 'key' => 'field_three', 'value' => $three ), ) ); }02/06/2019 at 2:28 pm #483821CRAIG HALLER
ParticipantWe are sort of on the same page.
Last week I followed this:
https://connections-pro.com/quicktip-custom-field-adding-a-text-field/and added a text field and then two checkbox fields. I did not use the “Custom Fields” in the back end since they were not mentioned in the article.
Now today I added a Custom Field in the back end.
I assume these are all the same things, handled the same way.
I will make sure I register and can import today’s field as well, and with that I will try to leave you alone today. I think I have a good handle on the system at this point.
But then, ya never know …
02/06/2019 at 4:31 pm #483830Steven Zahm
Keymaster@ Craig
Oh, ok, I understand … I highly recommend the registration vs using the “Custom Fields” metabox. The meta query and importing will work without registration but it is best to register.
-
AuthorPosts
You cannot reply to this support topic. Please open your own support topic.
