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 32 replies, 5 voices, and was last updated 7 years, 7 months ago by
Jmaes.
-
AuthorPosts
-
06/23/2015 at 2:20 pm #338229
James
GuestThank you very much!
I believe you had posted something about adding fields with multiple options? But now I can’t find it. I have two custom text fields and 3 fields with checkboxes.
06/23/2015 at 4:20 pm #338260Steven Zahm
Keymaster@ James
Adding a checkbox is only mildly more difficult. Here’s the code that to add two text fields and three checkboxes:
$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 Name 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_id_1', // 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 Name 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_id_2', // 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 Name 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. 'desc' => 'Checkbox Description', 'id' => 'field_id_3', // Change this so it is unique to you project. Each field id MUST be unique. 'type' => 'checkbox', // This is the field type being added. ), array( 'name' => 'Field Name Four', // 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. 'desc' => 'Checkbox Description', 'id' => 'field_id_4', // Change this so it is unique to you project. Each field id MUST be unique. 'type' => 'checkbox', // This is the field type being added. ), array( 'name' => 'Field Name Five', // 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. 'desc' => 'Checkbox Description', 'id' => 'field_id_5', // Change this so it is unique to you project. Each field id MUST be unique. 'type' => 'checkbox', // This is the field type being added. ), ), );
Displaying this in the template is a bit different because the checkbox is saved as either
1
(checked) or0
(not checked). So you would want to do this to display it in the template:$checked = $entry->getMeta( array( 'key' => 'field_id', // This should match exactly the field id used when registering the custom field. 'single' => TRUE // Do not change this. ) ); echo if ( $checked ) '<p>Checkbox was checked.</p>';
Hope that helps!
06/23/2015 at 5:50 pm #338263James
GuestPerfect! Thank you very much.
Is there a way to add a link to the ‘Edit my entry’ within other WP pages? Or even add specific fields from the the Directory? Like show the current users Name or Profile image?
Thanks
06/23/2015 at 7:21 pm #338270James
GuestHow can I display a group of checkboxes together?
For example, we have 9 different certifications that a person may have.
Certification Codes:
RPR (Registered Prefessional Reporter)
RMR (Registered Merit Reporter)
RDR (Registered Diplomat Reporter)
CRR (Certified Realtime Reporter)
CSR (Certified Shorthand Reporter)
CLVS (Certified Legal Video Specialist)
CMRS (Certified Manager of Reporting Services)
CRI (Court Reporting Instructor)
CPE (Certified Program Evaluator)Is it possible to have this in its own box/fieldset?
06/24/2015 at 10:05 am #338413Steven Zahm
Keymaster@ James
re: Is there a way to add a link to the ‘Edit my entry’ within other WP pages? Or even add specific fields from the the Directory? Like show the current users Name or Profile image?
Sorry, no. Do you have the Form extension? If you do, here’s a snippet that add a shortcode which will output the edit link:
add_shortcode( 'connections_edit_link', 'cn_edit_my_entry_shortcode' ); function cn_edit_my_entry_shortcode() { // Grab an instance of the Connections object. $instance = Connections_Directory(); // Get the current user ID. $userID = get_current_user_id(); // Check to see if the entry has been linked to a user ID. $entryID = get_user_meta( $userID, 'connections_entry_id', TRUE ); $results = $instance->retrieve->entries( array( 'id' => $entryID ) ); if ( is_user_logged_in() && ( $userID == $results[0]->user && $entryID == $results[0]->id ) && ( current_user_can( 'connections_edit_entry' ) || current_user_can( 'connections_edit_entry_moderated' ) ) ) { return cnURL::permalink( array( 'type' => 'edit', 'slug' => $results[0]->slug, 'text' => 'Edit My Entry', 'return' => TRUE ) ); } }
I just tossed it together so it is not really tested but should work. The shortcode is
[connections_edit_link]
.06/24/2015 at 10:24 am #338416Steven Zahm
Keymaster@ James
re: How can I display a group of checkboxes together? For example, we have 9 different certifications that a person may have.
You would need to use a checklist field These are only marginally more difficult to work with compared to the text field and checkbox field types. Building off the previous samples here’s how to add a checklist:
$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 Name 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_id_1', // 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 Name 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_id_2', // 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 Name 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. 'desc' => 'Checkbox Description', 'id' => 'field_id_3', // Change this so it is unique to you project. Each field id MUST be unique. 'type' => 'checkbox', // This is the field type being added. ), array( 'name' => 'Field Name Four', // 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. 'desc' => 'Checkbox Description', 'id' => 'field_id_4', // Change this so it is unique to you project. Each field id MUST be unique. 'type' => 'checkbox', // This is the field type being added. ), array( 'name' => 'Field Name Five', // 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. 'desc' => 'Checkbox Description', 'id' => 'field_id_5', // Change this so it is unique to you project. Each field id MUST be unique. 'type' => 'checkbox', // This is the field type being added. ), array( 'name' => 'Field Name Six', // 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' => 'certifications', 'type' => 'checkboxgroup', 'options' => array( 'RPR (Registered Prefessional Reporter)' => 'RPR (Registered Prefessional Reporter)', 'RMR (Registered Merit Reporter)' => 'RMR (Registered Merit Reporter)', 'RDR (Registered Diplomat Reporter)' => 'RDR (Registered Diplomat Reporter)', 'CRR (Certified Realtime Reporter)' => 'CRR (Certified Realtime Reporter)', 'CSR (Certified Shorthand Reporter)' => 'CSR (Certified Shorthand Reporter)', 'CLVS (Certified Legal Video Specialist)' => 'CLVS (Certified Legal Video Specialist)', 'CMRS (Certified Manager of Reporting Services)' => 'CMRS (Certified Manager of Reporting Services)', 'CRI (Court Reporting Instructor)' => 'CRI (Court Reporting Instructor)', 'CPE (Certified Program Evaluator)' => 'CPE (Certified Program Evaluator)', ), 'default' => '', ), ), );
Displaying this is where is gets “tricky” because it is stored as an array so you have to loop thru the saved values to display them like so:
$certifications = $entry->getMeta( array( 'key' => 'certifications', // This should match exactly the field id used when registering the custom field. 'single' => TRUE // Do not change this. ) ); if ( ! empty( $certifications ) ) { echo '<ul class="cn-certifications">'; foreach ( $certifications as $certification ) { printf( '<li class="cn-certification cn-%1$s">%2$s</li>', esc_attr( $certification ), esc_html( $certification ) ); } echo '</ul>'; }
This is not tested, but should work. Hope that helps!
06/24/2015 at 12:24 pm #338430James
GuestWhere would I put:
add_shortcode( 'connections_edit_link', 'cn_edit_my_entry_shortcode' ); function cn_edit_my_entry_shortcode() { // Grab an instance of the Connections object. $instance = Connections_Directory(); // Get the current user ID. $userID = get_current_user_id(); // Check to see if the entry has been linked to a user ID. $entryID = get_user_meta( $userID, 'connections_entry_id', TRUE ); $results = $instance->retrieve->entries( array( 'id' => $entryID ) ); if ( is_user_logged_in() && ( $userID == $results[0]->user && $entryID == $results[0]->id ) && ( current_user_can( 'connections_edit_entry' ) || current_user_can( 'connections_edit_entry_moderated' ) ) ) { return cnURL::permalink( array( 'type' => 'edit', 'slug' => $results[0]->slug, 'text' => 'Edit My Entry', 'return' => TRUE ) ); } }
Thanks!
06/24/2015 at 12:36 pm #338431Steven Zahm
Keymaster@ James
I would suggest adding it as a new snippet using the Code Snippets plugin.
06/24/2015 at 12:58 pm #338433James
Guest- The checkbox group code work perfect. Thanks again!
- I have added the shortcode code to a new snippet. After that I added
[connections_edit_link]
to a regular wordpress page but nothing showed up.
Thanks for your help.
06/25/2015 at 7:55 pm #338648Steven Zahm
Keymaster@ James
I just tried the code I gave you again, it does output a link for me. Maybe copy the code and try again. Make sure you activate the snippet. I know that got me a few times when adding new snippets.
-
AuthorPosts
You cannot reply to this support topic. Please open your own support topic.