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 5 replies, 2 voices, and was last updated 1 year, 10 months ago by
Steven Zahm.
-
AuthorPosts
-
08/09/2020 at 6:04 pm #527554
Gordon Werner
ParticipantGood morning.
I need to be able to add custom radio buttons to the admin … as there is no guide for custom radio buttons, I based this off of the checkbox group code.// Register the metabox and fields. add_action( 'cn_metabox', 'cn_register_810_document_support' ); function cn_register_810_document_support() { $atts = array( 'title' => '810 Document Support', // Change this to a name which applies to your project. 'id' => '810_document_support', // Change this so it is unique to you project. 'context' => 'normal', 'priority' => 'core', 'fields' => array( array( 'name' => '810 Document Support', // 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' => '810_document_support', // Change this so it is unique to you project. Each field id MUST be unique. 'type' => 'radio_inline', // This is the field type being added. 'options' => array( 'not_supported' => 'Not Supported', 'supported' => 'Supported', 'certification_pending' => 'Certification Pending', 'certified' => 'Certified', ), 'default' => 'not_supported', // This is the default selected option. Leave blank for none. ), ), ); cnMetaboxAPI::add( $atts ); }
This seems to work as it creates the appropriate radio buttons on the admin side … however … on the public side it just displays the KEY of the radio button (i.e. not_supported) as opposed the the NAME “Not Supported”
What do I need to do to change the card.php and card-single.php files to show the NAME of the button instead?
Also, what about CVS Import / Export? do I just use the code as found on the Customize Text Field page but change the field_id info to match my radio buttons?
thx.
Note: This is my first customization, so please be kind.
-
This topic was modified 1 year, 10 months ago by
Gordon Werner.
-
This topic was modified 1 year, 10 months ago by
Gordon Werner.
-
This topic was modified 1 year, 10 months ago by
Gordon Werner. Reason: fixing typos
08/09/2020 at 7:56 pm #527558Gordon Werner
ParticipantAlso … is it possible to add multiple radio button groups at the same time? so they show up in the same box in the admin manage page?
thx
08/09/2020 at 8:05 pm #527559Gordon Werner
ParticipantAlso … is it possible to add multiple radio button groups at the same time? so they show up in the same box in the admin manage page?
I have 10 of these groups I need added … all within the same box on the admin screen (preferably) … they all function the same way
thx
08/11/2020 at 1:42 pm #527649Steven Zahm
KeymasterRE: on the public side it just displays the KEY of the radio button (i.e. not_supported) as opposed the NAME “Not Supported” … What do I need to do to change the card.php and card-single.php files to show the NAME of the button instead?
What you are seeing is correct as the
key
is the value saved in the database. Dealing with radios, dropdowns, and checkboxes are more challenging when compared to the text fields.I deal with these by creating helper functions. It is probably easier to explain with an example. So let use the free Education Levels addon.
If you look at this line of code you’ll see I called a helper function to add the options instead of adding them directly to the fields array:
Here’s the link to that helper function:
As you see, it simply returns the array that you would have added to the fields array when registering the field.
To get the name of the option, in the template, get the key as you already did and created another helper function to get the name.
Here’s a link that that helper function use in the addon:
The add-on uses a Content Block to display the output in a template, so there is not a specific example I can give you. But, you only really need to register the field and use the two helper functions to get it to display in the template.
If you open a support ticket and attached your code, zipped, I can use your code and create a working example that you can build from.
RE: what about CVS Import / Export? do I just use the code as found on the Customize Text Field page but change the field_id info to match my radio buttons?
You could, but in the CSV file, you would get the key saved in the database and not the name. Depending on your use, that might be desired. If you want to import to and from by the name and not the key. That is trickier because you need to transform the key and name during import/export. Here’s I do it in the Education add-on:
- https://github.com/Connections-Business-Directory/Education-Levels/blob/master/connections_education_levels.php#L314-L333
- https://github.com/Connections-Business-Directory/Education-Levels/blob/master/connections_education_levels.php#L362-L381
You’ll notice that I use the same helper function that was used when registering the field.
I hope this helps!
08/11/2020 at 1:44 pm #527651Steven Zahm
KeymasterRE: is it possible to add multiple radio button groups at the same time? so they show up in the same box in the admin manage page?
I think I answered this in the other support thred, here:
08/11/2020 at 1:47 pm #527652Steven Zahm
KeymasterIf you need further help with this, please open a support ticket and I will definitely help you sort this out :)
-
This topic was modified 1 year, 10 months ago by
-
AuthorPosts
You cannot reply to this support topic. Please open your own support topic.