Skip Navigation

[Resolved] Calling a custom field’s contents in PHP

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

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 5 years, 8 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.

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)

This topic contains 3 replies, has 2 voices.

Last updated by matthewL-7 5 years, 8 months ago.

Assisted by: Minesh.

Author
Posts
#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

Languages: English (English )

Timezone: 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.