Hi many thanks for your reply. I am assuming the page that I must apply this to is as per the page in my attached screen shot. Please could you tell me why there is this error when I open that page and what must I do to solve this. Please see screen shot
Hi,
To investigate this error I'll need to see how this content template is set up in the admin area.
Can you please share temporary admin login details?
Note: Your next reply will be private and please make a complete backup copy, before sharing the access details.
regards,
Waqar
Hi Waqar, I trust you are well. I am just following up on my last message to you which included the login details. I'm , hoping you got them and all is order? Regards
Brad
Hi Brad,
Thank you for sharing the admin access.
While troubleshooting the error in the "Template for Companies" content template, I noticed that no company post was set to show the information from, in the preview settings.
I've selected one of them and the error is now gone.
( screenshot: hidden link )
regards,
Waqar
Ok great thank you. Not too sure what that was. So back to my original query. I wanted to add the company sectors to each company as per the attached screen shot. I tried now according to your answer a few days ago. But I don't think I did it correctly. Because now it shows numbers instead of the actual sector names like "mining", "agriculture" etc. Please see 2nd screenshot
Thanks for writing back.
This limitation of the check boxes type custom field is already known and under review:
https://toolset.com/errata/cannot-output-checkboxes-field-option-titles/
The single block or the Types field shortcode currently doesn't output the option titles and for that you'll have to register a custom shortcode:
add_shortcode( 'checkboxes', function( $atts = [] ){
// provide defaults
$atts = shortcode_atts(
array(
'field'=> 'null',
'separator' => ', '
),
$atts
);
$output = "";
global $post;
$field_settings = types_get_field( $atts['field'] );
$field_values = get_post_meta( $post->ID, 'wpcf-'.$atts['field'], false );
$field_value_options = array_keys( $field_values[0] );
$separator = "";
foreach ($field_value_options as $field_value_option) {
$field_value_option_title = $field_settings['data']['options'][$field_value_option]['title'];
$output .= $separator . $field_value_option_title;
$separator = $atts['separator'];
}
return $output;
});
The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through active theme's "functions.php" file.
After that, you can include a "Fields and Text" block in place of the "Single Field" block in the template and use this new custom shortcode like this:
[checkboxes field='sectors' separator=', ']
Hi Waqar, apologies I have no clue what this is now. So does this mean I cannot list the "Sectors" under each Companies profile. Just as I added the "Phone number" the "Address" the "Email" the "Website" and the "Contact persons name"?
I apologize, if my last message caused some confusion.
I meant that you can list the "Sectors" under each Companies profile, but some extra steps will be needed.
(I've added those steps for you now)
1. I've added the code for the custom shortcode at WP Admin -> Toolset -> Settings -> Custom Code.
2. I've also added the shortcode "[checkboxes field='sectors' separator=', ']" in the "Template for Companies".
( screenshot: hidden link )
You'll see that the relevant sector titles are now showing on the single company pages.
Thank you very much. I really appreciate your assistance. I think that will be all for now. I hope so 🙂
Sorry one more thing. If I edit the "Sector list" will it update on the companies profile automatically? For example on the "Hydac" company that you showed in your screen shot. The one sector is "Engineering, industrial" now I might want to edit that because it now looks like two sectors where in fact it is one sector. So I might change those to read something like, Engineering-Industrial, Engineering-Ports, and so on.
You're very welcome and glad that I was able to help 🙂
You can add, remove or rename the sector options and their titles and the code will keep showing them automatically.
Feel free to mark this ticket as resolved and start a new one, for each new question or concern.
My issue is resolved now. Thank you! I just wish I knew how I get hold of someone like Waqar for the future. If there is simple way please could you let me know how to do this