Skip Navigation

[Resolved] Child posts custom fields – how to return checkbox values rather than 'Array'

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 9 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 -
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 2 replies, has 2 voices.

Last updated by frankP-3 9 years, 4 months ago.

Assisted by: Dat Hoang.

Author
Posts
#271023

I am trying to: get the values of checkboxes for a child post using:
$child_posts = types_child_posts('credits-line-item');
foreach ($child_posts as $child_post) {
echo $child_post->fields['roles'];
}

I visited this URL: local install, can't provide url

I expected to see: the values of the checked boxes

Instead, I got: Array

#271250

Are you using the field 'roles' as a checkboxes field? Therefore $child_post->fields['roles'] will output an array instead of a string.

You need to loop this array again. The following is my example code:

$child_posts = types_child_posts('credits-line-item');
foreach ($child_posts as $child_post) {
	$field_roles = $child_post->fields['roles'];
	if (is_array ($field_roles)) {
		foreach ($field_roles as $field_role) {
			echo $field_role['0'];
		}
	}
}
#271388

Thank you so much, and thank you for posting example code, I have this working now.
Many thanks.

The forum ‘Types Community Support’ is closed to new topics and replies.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.