Skip Navigation

[Resolved] I want to get data of a custom field of a post type from a wordpress "page".

This support ticket is created 7 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 0.71 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 4 replies, has 2 voices.

Last updated by frederikeM 7 years, 3 months ago.

Assisted by: Luo Yang.

Author
Posts
#555017

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.

#555059

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/

#555236

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

#555467

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]

#555504

Thank you very much.

Your guide helped me to sort out the issue.