Skip Navigation

[Resolved] Can I use the display text of a select field option?

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, 1 month 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 4 replies, has 2 voices.

Last updated by kevinB-9 9 years, 1 month ago.

Assisted by: Shane.

Author
Posts
#291723

The situation is as follows:

I've made a custom field called 'Colors'. This is a select field.

The options in this custom field have the following structure:
[Display text] = [Color name, e.g. 'Nutmeg', 'Paprika', 'Carrot']
[Value] = [Hex color code]

Is there a way to retrieve the display text and the value?

#291977

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Kevin,

I'm assuming that you would like to display these texts on a page, correct me if I am wrong.

In order to do this you will need to follow the instructions here: https://toolset.com/documentation/user-guides/displaying-wordpress-custom-fields/

Please let me know if this helps.

#292290

Hi Shane,

Thanks for your reply. I am indeed trying to display this in a post.

The value is actually displayed in a child post, and I can display the value itself. But I would also like to use the option title. Is there any way to call this separately?

The following code gives me the value (the hex code):

$kleur = "";
if (!((get_post_meta($child_post->ID, 'wpcf-kleuren', TRUE))=='')) :
     $kleur = get_post_meta($child_post->ID,'wpcf-kleuren', TRUE);
endif;

I've tried to get the value with the title (the name of the color), like so:

$kleur_label = types_render_field("kleuren", array("show_name"=>"true", "id"=>$child_post->ID));

But the code above comes back as empty. Am I doing something wrong?

#292650

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Kevin,

If i'm following correctly then you will like to display the value and label of the select tag of a particular post within another post correct?

Please let me know if I am wrong.

If my assumptions are correct then you can achieve this by using this shortcode

[types field="email" id="7" show_name="true"][/types]

Replace the field name with the slug of the field that you want to display.
The ID should be the id of the post that you want to display the value of the field for.

Please let me know

#292840

Hi Shane,

Thanks for your reply, that was useful for me!

It wasn't totally what I was looking for, because I want to use title as a separate value. But by using a str_replace I can change the string to what I need.

Thanks for pointing me in the right direction!
-Kevin

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.