Skip Navigation

[Resolved] return custom field select option display text

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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 6 replies, has 3 voices.

Last updated by Minesh 7 months ago.

Assisted by: Minesh.

Author
Posts
#2698058
Screenshot 2024-05-16 at 10.35.56 AM.png

Dear Sir/Madam,

I have a custom field in select form, I code with get_post_meta($post_id, 'wpcf-session-title', true) and it return the value stored in database, how can I get return with the option display text?

#2698107

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

You need to use a Types API function to get the formatted value of fields rather than the raw value stored in wp_postmeta.

You can use the function types_render_field, as described on this page:

https://toolset.com/documentation/customizing-sites-using-php/functions/

#2698157
Screenshot 2024-05-16 at 8.46.27 PM.png

Dear Nigel,

I visit the article but no idea how to get the option display text, below is my snippet code

	$session_ids = toolset_get_related_posts( $scid, 'admission-session', 'parent', 100, 0, array(), 'post_id', 'child');
	
	$session_options = "";
	if ( $session_ids ){
		foreach ( $session_ids as $session_id) {
			$session_options .= sprintf("<option value='%s'>%s</option>", get_post_meta($session_id, 'wpcf-session-title', true), types_render_field("session-title", array('show_name' => true )));
		}
	}	

I want to build a select option according to the related post, could you please advise how? I attached the custom field structure for your reference.

#2698168

Further information, $scid is the child post id

#2698357

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

What if you try to use the Types PHP API function types_render_field() in order to display the select box selected option text.

$selected_option_text = types_render_field("session-title", array("id"=>$scid ));
echo $selected_option_text;
#2698361

Dear Minesh,

Thanks for your reply, it works but I would like to know more about the attributes that I can apply in array(), could you give me the site where I can know more? I did refer to https://toolset.com/documentation/customizing-sites-using-php/functions/#select but seems no such sample for reference.

#2698612

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

As you can see with the following doc:
- https://toolset.com/documentation/customizing-sites-using-php/functions/#select

All attributes are listed with the above docs you can use any of those.

For exammple:

$selected_option_text = types_render_field("session-title", array("item"=>$scid));
echo $selected_option_text;