Skip Navigation

[Resolved] How to convert raw database data to simple readable format?

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

Problem:
Custom fields with options that include special characters such as apostrophes when saved to the database have such characters escaped (e.g. "John\'s dog").

If you output these field values with raw output it shows the escaping.

Solution:
You can use the PHP stripslashes function in a custom shortcode to output the raw value without escaping, as described below: https://toolset.com/forums/topic/how-to-convert-raw-database-data-to-simple-readable-format/#post-920347

This support ticket is created 6 years, 4 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 4 replies, has 2 voices.

Last updated by Himanshu Agarwal 6 years, 4 months ago.

Assisted by: Nigel.

Author
Posts
#919828

I have created a custom select field, in which I have added "long text" in custom field content.

When I display custom field content as raw database, it converts apostrophe ( ' ) to apostrophe with slash ( \' ).

How can we keep apostrophe, double quotation marks etc. as it is when displaying?

#919962

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

I'm not sure it is possible to disable escaping special characters with the saved values, I'm checking with the developers.

You normally have a display value, and the saved value.

When you want to output the field you show the display value (the same string that appears in the select dropdown).

You don't want to display the display value, right? You want to output the value stored in the database, and this value has special characters, right?

#920147

Yes, I want to output the value stored in the database, and this value has special characters, but i don't want to display special characters.

#920347

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

I checked with the developers who said that is how WordPress stores the fields in the database, it isn't possible to prevent the escaping the special characters with backslashes.

However, when you retrieve these fields you can use the PHP function stripslashes to clean up the string: hidden link

In PHP you can retrieve the field with get_post_meta and then apply stripslashes.

If you need to do it where you insert the field with the types shortcode, you could register the following (simple, it could be improved) custom shortcode:

add_shortcode( 'strip-slashes', function( $atts, $content ){

	$content = apply_filters( 'the_content', $content );

	return stripslashes( $content );
});

and then use it like this:

[strip-slashes][types field='some-field'][/types][/strip-slashes]
#920649

Thank you Nigel, code is working wonderfully.