I have setup a post type A with checkboxes custom field named "Location", the "Locatoin" custom fields has bellow choices :
A1,A2,A3,A4.
On a wordpress page at frontend, I would like to list all choices of "Location" custom field (A1,A2,A3,A4) dynamiclly. I know how to render the custom field value of a post, but I dont know how to get all choices of a custom field.
Dear frederike,
The options of a custom checkboxes field is setup manually, so you will need to display all those choices manually, there isn't such a feature to display them dynamically.
And in your case, I suggest you setup a custom Hierarchical taxonomy to replace the custom checkboxes field, then you will be able to list all terms of the taxonomy with Views plugin easily:
https://toolset.com/documentation/user-guides/create-custom-taxonomies/
I know I can use custom-taxonomies, but I would not to use it !
On the backend, when add new item of the post type A, I can see the "location" custom field is loaded dynamically base on the options I setup on the Types. So I think we still have a way/functions somewhere to get the custom field show dynamically. Please assit.
Thank you
As I mentioned above there isn't such a built-in feature within Types plugin, you will need to setup a custom shortcode for it, for example:
1) Add below codes into your theme/functions.php
add_shortcode('checkboxes_options', 'checkboxes_options_func');
function checkboxes_options_func($atts, $content)
{
$atts = shortcode_atts( array(
'field' => 'location', // field slug
), $atts);
$wpcf_fields = get_option('wpcf-fields');
$res = '';
$arr = array();
if(isset($wpcf_fields[$atts['field']])){
$field = $wpcf_fields[$atts['field']];
if(isset($field['data']['options'])){
foreach($field['data']['options'] as $option){
$arr[] = $option['title']; //option title
//$arr[] = $option['set_value']; // option value
}
$res = implode(',', $arr); // here is the separator
}
}
return $res;
}
2) Then use above shortcode in the content, like this:
[checkboxes_options]
Thank you very much.
Your guide helped me to sort out the issue.