Skip Navigation

[Closed] Referenced a user custom field in child theme

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

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

This topic contains 1 reply, has 2 voices.

Last updated by Beda 4 years, 7 months ago.

Author
Posts
#1566559

Hi there,

I'm trying to figure out how to reference user custom field in a child theme template.

For example, I have added a checkbox with the values 0 or 1 as a custom user field. I would like to write a if statement in PHP, if custom_user_field_xyz is 1, display content.

Please could you give me an idea as to how to do that, the documentation (https://toolset.com/documentation/customizing-sites-using-php/functions/) isn't clear. I'm a little confused with the arrays.

Thank you in advance,
Kyle

#1566589

The array is used to specify the output method (raw, for example, if you do want only the value, not the wrapping HTML)

A Checkbox field, for example, is called like so in PHP:

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

This will output the checkbox value, you can try to see what it precisely outputs either using echo (a PHP function) or error_log(print_r($variable, true)); and populate $variable first with the types_render_field() function.

However, be careful with saving 0(zero) to the database:
https://toolset.com/errata/checkboxes-that-save-0-are-interpreted-as-checked-by-views/

You cannot use that in a View later, better is to save "real" values like strings or numeric (but not 0)

The topic ‘[Closed] Referenced a user custom field in child theme’ is closed to new replies.