Sauter la navigation

[Résolu] Converting mulitline to wysiwyg – again

This support ticket is created Il y a 2 années et 11 mois. 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)

Ce sujet contient 2 réponses, a 2 voix.

Dernière mise à jour par BorisG4880 Il y a 2 années et 11 mois.

Assisté par: Waqar.

Auteur
Publications
#2284933

I want to convert a multiline custom field into a wysiwyg field and I followed this instructions: https://toolset.com/forums/topic/convert-a-multiple-lines-custom-field-to-wysiwyg/
1) Open the Field group where the Multi line field is added ,
2) Remove the Multi line field (eg: book-summary)
3) Add a WYSIWYG editor field with the same field name (book-summary) as used in point 2
4) save the field group.

However, I can not safe the new field group because the slug is already taken. Entering a different slug obviously did not help. The fields are still visible in the frontend, but I can not edit them anymore as the multiline field is deleted in the field group and the wysiwyg field is not populated with the content.

Is there a way to make this happen? Or to restore the old version? I did make a backup but it failed 🙁

#2285517

Hi,

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

It is possible to restore the Toolset custom field, that has been removed from the field group. Please go to WP Admin -> Toolset -> Custom Fields and you'll see a button for "Post Field Control".

Clicking it will take you to the "Post Field Control" section which will show the fields which have been removed from the custom field group. The "Change assignment" link below the field can be used to put it back into the field group.
( screenshot: lien caché )

If you'd still prefer to use the same "book-summary" slug as the WYSIWYG field while maintaining the existing custom multiline field data, you can follow these steps:

Important note: Make a full backup copy of the website first and make sure to follow the steps in the order mentioned.

1. Add a new WYSIWYG field in the same field group, with a slug "book-summary-temp".

2. To copy the custom field values from the field "book-summary" to this new custom field, you'll need a custom shortcode:


add_shortcode('custom_copy_custom_fields', 'custom_copy_custom_fields_func');
function custom_copy_custom_fields_func( $atts ) {
	$a = shortcode_atts( array(
		'type' => '',
		'from' => '',
		'to' => ''
	), $atts );

	// get all the target posts
	$args = array(
		'post_type'        => $a['type'],
		'posts_per_page'   => -1,
		'post_status'      => 'any',
	);

	$posts = get_posts( $args );

	foreach ($posts as $post) {
		$from_value = types_render_field( $a['from'], array( 'item' => $post->ID, 'output' => 'raw', 'suppress_filters' => true ) );
		if(!empty($from_value)) {
			update_post_meta( $post->ID, 'wpcf-'.$a['to'], $from_value );
		}
	}
}

The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.

3. Add a new temporary page and include this new shortcode, so that 'type' attribute has the target post type slug, 'from' attribute has 'copy from' field slug, and 'to' attribute has 'copy to' field slug:


[custom_copy_custom_fields type="book" from="book-summary" to="book-summary-temp"]

Visit this temporary page after saving and this shortcode will cycle through all posts in the "book" post type and copy field data from the "book-summary" field to the "book-summary-temp" field.

4. Check the edit screen of a few book posts and once confirmed that the field data has been copied, remove the custom shortcode from the page and save it.

5. Remove the "book-summary" field from the field group and then delete it from the "Post Field Control" section.

6. Visit the field group again and add a new WYSIWYG field with the same slug "book-summary". It will not show so the warning message this time.

7. To copy the field data from the "book-summary-temp" field back to the "book-summary" field, you can use the custom shortcode again on the temporary page, but, this time switching the 'from' and 'to' attributes:


[custom_copy_custom_fields type="book" from="book-summary-temp" to="book-summary"]

8. Once confirmed that the field data has been copied to the new WYSIWYG field, you can delete the temporary page with the shortcode and remove the "book-summary-temp" field from the field group and the "Post Field Control" section.

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

regards,
Waqar

#2287421

Thanks a lot Waqar. I am more than happy that you showed me the Post Field Control. That made my life a lot easier. Thanks also for the detailed instructions on moving content form on field group to another. I will give it a try as soon as I have more time. As this is unlikely to be the case in the next couple of weeks you can close this ticket. I will reach out again should I have any trouble then.
All the best,
Boris