Skip Navigation

[Resolved] Need to save ampersand in post_title from CRED form

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

Problem:

I have a cred form that adds or updates a custom post type. When saving a valid post_title with a & in the name, it gets changed to the HTML character

Solution:

You can try with the API action "cred_save_data":
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
This hook allows doing a custom action when post data is saved to database.

Replace all those with "&" in the post title

Relevant Documentation:

https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

This support ticket is created 3 years, 1 month 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 2 replies, has 2 voices.

Last updated by jeffC-3 3 years, 1 month ago.

Assisted by: Luo Yang.

Author
Posts
#2253711

I have a cred form that adds or updates a custom post type. When saving a valid post_title with a & in the name, it gets changed to the HTML character of it & amp ; (no spaces between). If I update the post in wp-admin, it saves just &. I found this article that appears to answer the reason why:
https://wordpress.stackexchange.com/questions/185587/updating-a-post-without-escaping-ampersands

I found this answer for Toolset but it doesn't help:
https://toolset.com/forums/topic/ampersand-in-post-title/

That is because I have a mobile app reading the WP database and thus getting the HTML character instead of just &. Instead of requiring everybody who wants to read the value from the database and instead have Toolset store it correctly like wp-admin does, how can I get around this issue in Toolset?

#2253979

Hello,

You can try with the API action "cred_save_data":
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
This hook allows doing a custom action when post data is saved to database.

Replace all " & amp ;" with "&" in the post title:
hidden link
https://developer.wordpress.org/reference/functions/wp_update_post/

#2254319

Hi Luo. Thanks for the suggestions. I have a Toolset developer I am working with and he found the solution:

		$title = get_the_title($post_id);
		$ftitle = html_entity_decode($title);
		$args = array('ID' => $post_id, 'post_title' => $ftitle);
		wp_update_post($args);

Thanks for your help!