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?
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/
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.
Further information, $scid is the child post id
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;
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.
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;