Skip Navigation

[Resolved] PHP Fatal error: Call to undefined function types_render_field()

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

Problem: I am seeing an error:

PHP Fatal Error: Call to undefined function types_render_field()

Solution: Wrap your function call in a conditional that tests whether the function exists:

if (function_exists('types_render_field')){
  $value = (types_render_field( 'url', array( ) ));
  return $value;
}

Relevant Documentation: https://toolset.com/documentation/customizing-sites-using-php/functions/

This support ticket is created 6 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.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 12 replies, has 2 voices.

Last updated by georgeaG 6 years, 8 months ago.

Assisted by: Christian Cox.

Author
Posts
#550867

I am trying to save a page that contains shortcodes that I developed using types_render_field

Part of the code:

function uvt_show_adsl() {

ob_start();

$args = array(
'post_type' => 'internet-connection',
'post_status' => 'publish',
'suppress_filters' => TRUE,
'posts_per_page' => '4',
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'service-type',
'field' => 'slug',
'terms' => 'adsl'
),
array(
'taxonomy' => 'service-type',
'field' => 'slug',
'terms' => 'annex-m'
)
)
);

$services = array();

$results = new WP_Query($args);
if ($results->have_posts()) {
while ($results->have_posts()) {
$results->the_post();
$services[types_render_field('service-order', array())] =
array('daisy-product-code' => types_render_field('daisy-product-code', array()),
'service-name' => get_the_title(),
'installation-charge' => types_render_field('installation-charge', array()),
'installation-charge-tip' => types_render_field('installation-charge-tip', array()),
'migration-charge' => types_render_field('migration-charge', array()),
'migration-charge-tip' => types_render_field('migration-charge-tip', array()),
'termination-charge' => types_render_field('termination-charge', array()),
'usage' => types_render_field('usage', array()),
'static-ip-address-included' => types_render_field('static-ip-address-included', array()),
'30-days-price' => types_render_field('30-days-price', array()),
'12-months-price' => types_render_field('12-months-price', array()),
'24-months-price' => types_render_field('24-months-price', array()),
'download-speed' => types_render_field('download-speed', array()),
'upload-speed' => types_render_field('upload-speed', array())
);
}
}

The code works and show all the information: hidden link but I can't update the page because it returns 500 error and when I check the error log, this is what is in there:

AH01071: Got error 'PHP message: PHP Fatal error: Call to undefined function types_render_field() in /var/www/vhosts/ultraview.net/httpdocs/wp-content/themes/ultraview-telecom/inc/shortcodes/shortcodes.inc on line 115\n', referer: hidden link

#551048

Hi, when is the uvt_show_ads function called? What action hook is it responding to, or what sequence of events triggers it?

It looks like a timing issue, maybe it's being fired before Types is ready?

#551050

Oh my mistake, I believe I misinterpreted what you wrote. You're saying the shortcode works, and the page shows the correct information, but you get a 500 error when you try to update the page, correct?

If possible, could you copy + paste the contents of your page (html, not Visual Editor) into your reply? I will take a look and see if anything seems obviously problematic.

#551056

Hi Christian,

Thanks for getting back to me.

The code is just a call to the shortcode - [shortcode_name].

I've replaced types_render_field with get_post_meta and the error stopped. But what I find weird is that I have the plugin installed in other sites and I use types_render_field without any issue.

Shall I keep the get_post_meta?

#551058

That is strange, if get_post_meta is working for you I say stick with it for now. I'm curious about your other plugins and theme, and if there's some conflict with Toolset. If you'd like to continue debugging, we can try to pin it down. If you're satisfied with get_post_meta, no need to continue debugging.

Here are the troubleshooting steps I would try:
- Temporarily disable all non-Toolset plugins and enable a default theme like Twenty Seventeen, retest.
- If the problem is resolved, then there is a conflict somewhere. Reactivate your parent theme, then child theme, then plugins one by one until the conflict is revealed.
- If the problem is not resolved, I will need to investigate further by making a clone of your site and running some tests locally. If that's okay with you, please provide login credentials in the private reply fields here.

#551059

Private reply fields enabled.

#551061

Hi Christian,

Many thanks. I will do it and get back to you ASAP.

#551103

Hi Christian, the issue is with Yoast SEO.

I deactivated all plugins and start activating one at time. All fine until I activated Yoast SEO.

I'm using the version 5.0.2 (for Yoast SEO).

Any thoughts?

Many thanks.

#551741

Okay thanks, I'm not able to reproduce the error using a basic installation with a default theme and Yoast 5.0.2 (free version), so I'm going to need to create a clone of your site for further investigation. If that's okay with you, please provide login credentials here in the private reply fields. I will install the Duplicator plugin and create a clone of your site, then perform my tests locally.

#552725

Okay, thanks. I've taken a look at your site and I'm able to reproduce the issue locally. Furthermore, I can reproduce the issue with a default theme and only Types, Views and Yoast installed. So there appears to be an issue with using types_render_field in a shortcode when Yoast is active. I am reaching out to our 2nd tier support team for some clarification here, as I am not completely sure if this is a bug or if there is a reason this cannot work as expected. Please continue to use get_post_meta and I will update you when I have some more information.

#552732

Great. Thanks. Looking forward to hearing from you.

#558178

Hi, our development team has offered the following solution - please wrap your types_render_field API calls in conditionals that test if the types_render_field function is defined:

if (function_exists('types_render_field')){
  $value = (types_render_field( 'url', array( ) ));
  return $value;
}

This should prevent an error from appearing when the function is called too early in the WP request lifecycle. Please let me know if this does not resolve the issue.

#559474

Thanks, I'll do it.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.