Skip Navigation

[Resolved] types_render_field with argument ‘output’ => ‘raw’ still renders/does shortcode

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

Problem:

The attribute 'output' => 'raw' does not work with custom WYSIWYG field.

Solution:

It is fixed in Types plugin version 3.1, you can download it here:
https://toolset.com/account/downloads/

Relevant Documentation:

This support ticket is created 5 years, 10 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
- 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/Hong_Kong (GMT+08:00)

This topic contains 14 replies, has 2 voices.

Last updated by q1 5 years, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#913044

q1
PHP Inspect.png
PHP Debug.png
DB.png

Hi,

I am trying to get the raw (database content) from a custom types field using types_render_field() with 'output' => 'raw'. I need the shortcode to extract the image ids. This worked fine until I updated Types from 2.1 to 3.0.1. So manually changing the type or structure is not an option.

I checked the database if the content had been changed while updating Types and the database still has the raw shortcode.

So I debugged the code and saw that in the file /wp-content/plugins/types/application/models/field/service.php the function public function render_frontend() at line 137 (

$output = $view->render();

) converts/renders the gallery shortcode into html source code.

Could you help me figure out if I am using types_render_field() wrong or if maybe there's a bug in Types?

I attached some screenshot so you can check the values.

Thanks a lot for your help!

#913253

Hello,

How do you setup the custom field "image-gallery"? is it a custom text field? can you take a screenshot for it?
How do you setup your PHP codes? can you copy/paste it here?

I need to test and debug it in my localhost, thanks

#913345

q1
CF in custom post (view).png
CF Setup 2_2.png
CF Setup 1_2.png
CF in custom post (text).png

Hi,

I am using a WYSIWYG which allows the user to create a gallery using WordPress native behaviour. I attached some screenshot as you asked.

Here's the code I am using


...
$sliderItems = localizedContent($exhibition->ID, 'image-gallery', $exhibition->post_type, 'metadata', true, 'fr', array('output' => 'raw', 'suppress_filters' => 'true'));
...

function localizedContent($id, $field, $type, $returnType = 'id', $raw = false, $lang = ICL_LANGUAGE_CODE, $args = array()) {
    $original = get_wpml_object_id($id, $type, true, $lang);

    $result = false;

    if ($returnType === 'id') {
        $result = $original;
    }
    if ($returnType === 'metadata') {
        $result = getMetadata($field, $original, $raw, $args);
    }
    if ($returnType === 'text') {
        $result = get_post($original)->$field;
    }

    if (!$result) {
        $original = get_wpml_object_id($id, $type, true, 'fr');

        $result = false;

        if ($returnType === 'id') {
            $result = $original;
        }
        if ($returnType === 'metadata') {
            $result = getMetadata($field, $original, $raw);
        }
        if ($returnType === 'text') {
            $result = get_post($original)->$field;
        }
    }

    return $result;
}

...
function getMetadata($fieldName, $id, $raw = false, $args = array()) {
    if ($raw) {
        return types_render_field($fieldName, array_merge(array('post_id' => $id, 'output' => 'raw'), $args));
    }
    else {
        return types_render_field($fieldName, array_merge(array('post_id' => $id), $args));
    }
}
...

Thanks for your help!

#913351

You can use wordpress built-in function get_post_meta to get custom field value, for example, modify this line from:

return types_render_field($fieldName, array_merge(array('post_id' => $id, 'output' => 'raw'), $args));

To:

return get_post_meta($id, 'wpcf-' . $fieldName, true);
#913357

q1

Yes, I also thought of that solution. But I am unsure if it is a good one since types_render_field() also allows you to pass other attribute arguments. Are they being ignored when 'output' => 'raw' is also being passed as argument?

In this special case your solution would work but I have a lot of code in many places and other projects which could break.

#913669

Yes, you are right, the attribute 'output' => 'raw' does not work, it is a known bug, I have added this thread into our to-do list, And our developers are working on it, I will update this thread if there is anything news.

Since you are going to get the raw value of the custom field, I don't think you need other parameters, so in this case, you can use wordpress function "get_post_meta" instead of Types function "types_render_field"

#913796

q1

Ok, thanks for the confirmation.

I will wait for the bugfix and in the meantime use the workaround.

#914508

Thanks for the patience, our developers are working on it, I will update this thread if there is anything news.

#919692

Here is the feedback from our developers:
This will be fixed with the upcoming release Types plugin version 3.0.2, it should be release soon.

#921207

q1
Screen Shot 2018-07-05 at 12.01.54.png

Hi,

I noticed that the update has been recently released and tested the fixed. Unfortunately the update didn't solve the issue.

I attached a screenshot which shows the watch of the function when debugging (with the arguments).

Thanks for your help!

#958763

Thanks for the feedback, I can duplicate the same problem with custom WYSIWYG field, and put it int our to-do list, our developers will take care of it.

#1076236

Here is the feedback from our developers:
The issue will be fixed with the next release of Types plugin. In about 2-3 weeks.

#1076261

q1

Hi,

thanks for the feedback and great to hear!

#1110215

Types plugin version 3.1 is released, you can download it here:
https://toolset.com/account/downloads/
Please test and feedback if the problem is fixed.

#1110519

q1

Hi,

thanks for the update and yes it works now! 🙂

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