Navigation überspringen

[Gelöst] Calling a custom field’s contents in PHP

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem:
Calling a custom field's contents in PHP

Solution:
you should use the Types fields API PHP function types_render_field() to get the value of your custom field.

$value = types_render_field("is-the-offer-a-gambling-offer", array("output"=>"raw"));

Relevant Documentation:
=> https://toolset.com/documentation/customizing-sites-using-php/functions/#select
=> https://toolset.com/documentation/customizing-sites-using-php/

This support ticket is created vor 5 Jahren, 8 Monaten. 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.

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)

Dieses Thema enthält 3 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von matthewL-7 vor 5 Jahren, 8 Monaten.

Assistiert von: Minesh.

Author
Artikel
#1263481

Hi,

I have a couple of questions about using a custom field and conditional formatting but in PHP code as opposed to using the visual editor to do it.

I have a field with the field slug "is-the-offer-a-gambling-offer", it is a select field with the contents of the field set to 1 or 2.

The code I am trying to use is relatively simple but its not working:

if ($wpcf-is-the-offer-a-gambling-offer = 2)
  echo "Some text";

Do I need to do something else to be able to call the field? Am I missing something.

#1263647

Minesh
Supporter

Sprachen: Englisch (English )

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

Hello. Thank you for contacting the Toolset support.

Well - you should use the Types fields API PHP function types_render_field() to get the value of your custom field.

For example:

$value = types_render_field("is-the-offer-a-gambling-offer", array("output"=>"raw"));

if ($value == 2){
   // add something here
}

More info:
=> https://toolset.com/documentation/customizing-sites-using-php/functions/#select
=> https://toolset.com/documentation/customizing-sites-using-php/

#1264283

Great thanks. 🙂

#1264293

All sorted.