Skip Navigation

[Resolved] PHP Get Select field display text

This thread is resolved. Here is a description of the problem and solution.

Problem:

How to display the label (Display Text) of the select tag of a particular post within another post in PHP

Solution:

You can use the shortcode below:

[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.

In PHP to run the shortcode you can use:

https://developer.wordpress.org/reference/functions/do_shortcode/

Relevant Documentation:

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

This support ticket is created 2 years, 9 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.

This topic contains 4 replies, has 2 voices.

Last updated by collectiveU 2 years, 9 months ago.

Assisted by: Christopher Amirian.

Author
Posts
#2337503
SelectField.png

Hi,

On PHP side, with select field options, using the values, what is the best way to get the Display text? or alternatively, where is the related display text for the raw value stored?

Cheers

#2338159

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

To get the values of a select field please us this code:

types_render_field("field-slug", array("output"=>"raw"));

And for the label of the values use this code:

types_render_field("field-slug", array("output"=>"html"));

Change "field-slug" with the slug of your custom field.

For more information:

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

Thank you.

#2338243

Hi Chris,

Correct me if I'm wrong but this is for the actual field where as I'm referring to the "Display text" of the "content field type" value in the related postmeta field.?

Cheers

#2338633

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

If I'm following correctly then you will like to display the label (Display Text) of the select tag of a particular post within another post correct?

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.

In PHP to run the shortcode you can use:

https://developer.wordpress.org/reference/functions/do_shortcode/

Thank you.

#2338643

Thanks, the following worked.

$event_type = do_shortcode( '[types field="event-type" id="' . $id . '" show_name="false"][/types]' );