Passer la navigation

[Résolu] PHP Get Select field display text

Ce fil est résolu. Voici une description du problème et la solution proposée.

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 Il y a 4 years, 2 months. 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.

Ce sujet contient 4 réponses, a 2 voix.

Dernière mise à jour par collectiveU Il y a 4 years, 2 months.

Assisté par: Christopher Amirian.

Auteur
Publications
#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

Les langues: Anglais (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

Les langues: Anglais (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]' );