Navigation überspringen

[Gelöst] Upgrade from Version 2.3.5 with newly purchased Toolset

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem:

The customer was upgrading their site running Toolset Version 2.3.5 to the latest version while also updating PHP to version 7.x. They needed guidance on the upgrade path and encountered issues displaying custom fields with legacy PHP code after the update. Despite the fields being visible in the Classic Editor, embedding Toolset shortcodes in the editor caused site crashes when running PHP 8.2.

Solution:

Solution:

1- Upgrade Path: It was recommended to deactivate and delete the old version of Toolset, update PHP to version 7.x, install the new Toolset version, and import custom fields if necessary. The customer's data was safely retained in the WordPress database throughout this process.

2- Custom Field Display:
To replicate the legacy PHP logic, it was advised to use Toolset Views with conditional shortcodes, such as:

[wpv-conditional if="( NOT(empty($(wpcf-trail-length))) )"]
   <h4>Your HTML here</h4>
   [types field="wpcf-trail-loc"][/types]<br />
   [types field="wpcf-trail-land"][/types]<br />
[/wpv-conditional]

If continuing with PHP code, the prefix wpcf- remains unchanged. The get_post_meta() function should be used to retrieve custom fields:

$loc = get_post_meta($post_id, 'wpcf-trail-loc', true);

3- Compatibility Notes: The customer was advised to update the PHP retrieval methods to align with current standards and replace older code constructs. The errors reported were related to the use of the continue statement and outdated plugin code.

Relevant Documentation:

https://toolset.com/documentation/programmer-reference/views/views-shortcodes/
https://developer.wordpress.org/reference/functions/get_post_meta/

This support ticket is created vor 7 Monaten, 3 Wochen. 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 -

Zeitzone des Unterstützers: America/Sao_Paulo (GMT-03:00)

Dieses Thema enthält 6 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von Mateus Getulio vor 7 Monaten, 3 Wochen.

Assistiert von: Mateus Getulio.

Author
Artikel
#2780050
#2780140

Mateus Getulio
Unterstützer

Sprachen: Englisch (English )

Zeitzone: America/Sao_Paulo (GMT-03:00)

Hi Sandra,

Thank you for reaching out! Since you're working in a staging environment, you're in a good position to safely update Toolset and PHP without impacting your live site.

To address your question:

1. All your custom fields and Toolset data are stored in your WordPress database. This means that deactivating and deleting the old Toolset plugin (Version 2.3.5) will not remove your data, so you're safe to proceed with the steps you've outlined.

2. Upgrade Path:
- First, go ahead and deactivate and delete the old version of Toolset (Version 2.3.5).
- Then, update your PHP version to 7.x.
- Once PHP is updated, install the latest version of Toolset you downloaded. You can do this by going to **Plugins > Add New > Upload Plugin** in your WordPress admin area, selecting the new Toolset plugin file, and activating it.
- After installation, you can import any custom fields if needed.

3. With the latest Toolset Types version installed, the automatic updater should handle the other Toolset plugins updates smoothly. However, if you encounter any issues with updates, you can always download the latest versions directly from your Toolset account here: [Toolset Downloads](https://toolset.com/account/downloads), and upload them manually through Plugins > Add New > Upload Plugin.

Please let us know if you have any further questions or run into any issues. We’re here to help!

Best regards,
Mateus

#2780154
Toolset Dashboard ‹ Florida Hikes — WordPress.png

Thank you. That worked perfectly. However, my legacy PHP code to display the custom fields from Toolset does not. My site is 18 years old and I'm used to coding HTML and, when I need to, PHP and CSS. What I'd set up in functions.php was an IF statement that if the content was from a certain category, replace the usual display of date & author at the top of the post with destination information with links, creating a cross-referenced index.

It's worked great for years, you can see a front-end example here, above the social icons: versteckter Link

I think I started this before you had Views, so I did the logic in php. I'm not quite ready to move to Gutenberg yet, and have over 2,000 pages on the website. So I'm not ready for Blocks.

Should I go ahead and install Views and use shortcodes to display that output? In the back end of Toolset, it's giving me these warnings about archives but since I can't back up my staging site, I'm a little worried about what might happen when I click that Resolve button.

Thank you again for your assistance.

#2780160
Screenshot 2024-10-31 Edit Post “Lakewood Park” ‹ Florida Hikes — WordPress.png

Here's what the fields (per the example above) I created with Tools long ago look like in the Classic Editor.

#2780167
Tools PHP display code for FloridaHikes.png

And here is the logic I use to display those fields in the front end in lieu of author / date on posts. I added this to functions.php for whatever theme I had in use at the time.

(Screenshot since it is PHP code)

If I can replicate using Views, great! But it isn't working on my staging site. I'm curious if you've renamed the wpcf- field prefix to something different in your current release and that's my problem. Do let me know. Thank you!

#2780200

I tried to use the toolset shortcodes provided but the staging site crashed whenever I attempted to use Classic Editor after I embedded some shortcodes generated by the shortcode tool. These are a couple of log entries that maybe you can make sense of.

[31-Oct-2024 13:53:29] WARNING: child 1856 said into stderr: "NOTICE: PHP message: PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /www/wp-content/plugins/types/vendor/toolset/types/embedded/includes/wpml.php on line 646"
[31-Oct-2024 13:53:29] WARNING: child 1856 said into stderr: "NOTICE: PHP message: PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /www/wp-content/plugins/types/vendor/toolset/types/embedded/includes/wpml.php on line 663"

I am on php 8.2 and WordPress 6.6.2
I still need to know how I can safely display the trails-related metadata I can see and edit in the Classic Editor on the front end. Thank you.

#2780218

Mateus Getulio
Unterstützer

Sprachen: Englisch (English )

Zeitzone: America/Sao_Paulo (GMT-03:00)

Hi Sandra,

Thank you for the detailed information and screenshots! I understand that you'd like to replicate your legacy PHP setup using Toolset Views while keeping the Classic Editor, especially to display custom fields for trail-related posts. Here’s how you can approach this:

You can indeed use Toolset Views to set up conditional logic similar to your original PHP code, which checks for specific custom fields and displays them if they’re present. Here’s a basic example using Toolset’s conditional shortcodes among other fields:

[wpv-conditional if="( NOT(empty($(wpcf-trail-length))) )"]
   <h4>Your HTML here</h4>
   [types field="wpcf-trail-loc"][/types]<br>
   [types field="wpcf-trail-land"][/types]<br>
[/wpv-conditional]

This shortcode checks if the custom field wpcf-trail-length is not empty and, if so, outputs the HTML within it. You can find more on Views shortcodes in our Views Shortcodes Documentation, including the conditional shortcode details here: https://toolset.com/documentation/programmer-reference/views/views-shortcodes/

You can combine it with some other useful shortcodes, eg.: wpv-post-author to show the author information, [types field="wpcf-field-slug"][/types] to render a custom field, and many others.

You could create/edit the template that page belong to and use the Toolset shortcodes to do it.

If you prefer to keep your original PHP logic, you can adapt it slightly to align with recent WordPress and PHP standards. The prefix wpcf- remains unchanged, so no modifications are needed there. However, for compatibility, try replacing your theme's custom field retrieval method with get_post_meta(https://developer.wordpress.org/reference/functions/get_post_meta/) as follows:

$loc = get_post_meta($post_id, 'wpcf-trail-loc', true);

Simply pass the post_id as an argument to retrieve your custom field data, which should function within your existing theme code. Within your theme’s hook, $post->ID should give you the post ID if it’s available, allowing you to retrieve field values without changing much of your original code structure.

The warning message that is shown in the screenshot, was included in the older versions of the Toolset Types plugin. It would act as a reminder that some custom fields exist for a specific post type, but they are not shown on the front-end using either code in the theme or through the Toolset Views plugin, you could disregard those.

Best regards,
Mateus