Skip Navigation

[Resolved] Help with types_render_field

This support ticket is created 5 years 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

This topic contains 6 replies, has 2 voices.

Last updated by matthewC-9 5 years ago.

Assisted by: Waqar.

Author
Posts
#1362231

I'm trying to display content from a repeatable field group, similar to https://toolset.com/forums/topic/display-repeatable-groups-of-fields-using-php/.

I've got the first part working - toolset_get_related_posts is grabbing the correct IDs for the repeatable field groups:
$location_features = toolset_get_related_posts(
$post->ID,
'unique-features',
array(
'query_by_role' => 'parent',
'return' => 'post_id',
'role_to_return' => 'child',
)
);

But when I get to the second step, this doesn't seem to be working:
foreach($location_features as $location_feature) {
echo $location_feature;
echo types_render_field( "wpcf-feature-name", array("output" => "normal", "id" => $location_feature ));
}
The ID gets echoed by the first line within the loop (so it seems like the loop itself is fine), but the second doesn't do anything. wpcf-feature-name is the meta-key for that field according to what I see in the database.

What do I need to do differently here?

#1362333

Hi Matthew,

Thank you for contacting us and I'd be happy to assist.

The "types_render_field" function expects the target post's ID through the attribute "item":
https://toolset.com/documentation/customizing-sites-using-php/functions/

If the "$location_feature" holds the target post's ID correctly, you can replace:


echo types_render_field( "wpcf-feature-name", array("output" => "normal", "id" => $location_feature ));

With:


echo types_render_field( "wpcf-feature-name", array("output" => "normal", "item" => $location_feature ));

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#1362703
toolset-render-echo.PNG
toolset-render-db.PNG

Hi Waqar! Thanks for the response. I tried using the updated code you sent, but I'm still not seeing the field content echoed - attaching screenshots of what I see in the database for one of the posts in question and what's getting printed on the page. What else should I try?

#1363093

Hi Matthew,

From the screenshots, the data seems to be stored correctly and should be shown through that code.

Can you please share a clone/snapshot of your website, along with the information about where this code can be seen?
( ref: https://toolset.com/faq/provide-supporters-copy-site/ )

This will allow me to troubleshoot this in more detail, on my own server.

Note: Your next reply will be private.

regards,
Waqar

#1363979

Thank you for sharing these details and the duplicator package.

I'm downloading it now and will update you with the findings, as soon as this troubleshooting completes.

#1364281

Hi Matthew,

Thank you for waiting.

During troubleshooting, I noticed that the "types_render_field" function is using the custom field slug with the prefix "wpcf-", which is only needed when using WordPress' native functions ( e.g. get_post_meta ).

With the Toolset's own "types_render_field" function, only field slug (without that prefix) should be used.
( ref: https://toolset.com/documentation/customizing-sites-using-php/functions/ )


types_render_field( "feature-name", array("output" => "normal", "item" => $location_feature ));

This should do the trick and please accept my sincere apologies, as I really should've spotted that in the first reply.

regards,
Waqar

#1364435

Hooray, that did the trick. Thanks again!