Skip Navigation

[Resolved] want to migrate toolset relationship

This support ticket is created 4 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Author
Posts
#1400573
Screenshot_6.jpg

Hi,

I want to update the toolset relationship but its showing some code needs to be updated.

Theme files file: /wpo365/functions.php - line 163, column 45 _wpcf_belongs_local-source_id",true
Theme files file: /wpo365/functions.php - line 164, column 50 _wpcf_belongs_connector_id",true);
Theme files file: /wpo365/functions.php - line 178, column 45 _wpcf_belongs_data-provider_id",tru
Theme files file: /wpo365/functions.php - line 179, column 49 _wpcf_belongs_connector_id",true);
Theme files file: /wpo365/functions.php - line 194, column 43 _wpcf_belongs_local-source_id",true
Theme files file: /wpo365/functions.php - line 195, column 46 _wpcf_belongs_connector_id",true);
Theme files file: /wpo365/functions.php - line 197, column 79 _wpcf_belongs_connector_id' AND met
Theme files file: /wpo365/functions.php - line 211, column 43 _wpcf_belongs_data-provider_id",tru
Theme files file: /wpo365/functions.php - line 212, column 46 _wpcf_belongs_connector_id",true);
Theme files file: /wpo365/functions.php - line 213, column 79 _wpcf_belongs_connector_id' AND met
Theme files file: /wpo365/functions.php - line 233, column 43 _wpcf_belongs_local-source_id",true
Theme files file: /wpo365/functions.php - line 234, column 46 _wpcf_belongs_connector_id",true);
Theme files file: /wpo365/functions.php - line 235, column 79 _wpcf_belongs_connector_id' AND met
Theme files file: /wpo365/functions.php - line 249, column 43 _wpcf_belongs_data-provider_id",tru
Theme files file: /wpo365/functions.php - line 250, column 46 _wpcf_belongs_connector_id",true);
Theme files file: /wpo365/functions.php - line 251, column 79 _wpcf_belongs_connector_id' AND met
Theme files file: /wpo365/my-account-documentation.php - line 43, column 20 _wpcf_belongs_product_id',

Please check attached screenshot for more clarification. what should I need to do for the proper working of the relationship without losing my data and functionality.

#1400975

Hello, it looks like there is some custom code in your theme's functions.php file that relies on the old method of establishing post relationships, which is using a custom field _wpcf_belongs_{slug}_id. When you migrate to the new post relationships systems, this code must be updated to work with the new relationships framework. I will be glad to take a look at your theme's functions.php file and determine which updates must be made, and you can browse the new Post Relationships API information here:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api

Please create a zip file containing your theme's functions.php file, and post a download link here for me to review. I'll take a closer look and get back to you with some suggestions.

#1401339

Hi Christian,

Thank you for the prompt response. Here is the theme files zip: hidden link

#1402193

Okay I looked at both of these files and I don't see any false positives here. All the code that was caught by the migration tool should be updated to work with the new relationships syntax. For example, starting at line 163 of functions.php:

$post_meta_id  .= get_post_meta($post_id,"_wpcf_belongs_local-source_id",true);
$post_cont_id  .= get_post_meta($post_meta_id,"_wpcf_belongs_connector_id",true);

Instead of using get_post_meta to get the parent post ID, you should now use the API toolset_get_parent_post_by_type:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_parent_post_by_type

$post_meta_id = toolset_get_parent_post_by_type( $post_id, 'local-source' ); // assuming local-source is parent post type slug
$post_cont_id = toolset_get_parent_post_by_type( $post_meta_id, 'connector' ); // assuming connector is parent post type slug

The code above can also be used as a template to resolve the functions.php errors on the following lines:
178
179
194
195
211
212
233
234
249
250

Now let's look at functions.php line 197:

$results  = $wpdb->get_results( "SELECT * FROM wp_postmeta WHERE meta_key = '_wpcf_belongs_connector_id' AND meta_value = $post_cont_id
",OBJECT);

It looks like you want to find "trigger" posts that are children of the Connector post with $post_cont_id as the Connector post ID. Now you can use the toolset_get_related_posts API to accomplish this:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts

$results = toolset_get_related_posts(
		// get posts related to this one
		$post_cont_id,

		// legacy relationship array syntax
		array( 'connector', 'trigger'),

		// additional arguments
		[
			'query_by_role' => 'parent',
			'limit' => 10000,
			'offset' => 0,
			'args' => [],
			'role_to_return' => 'other',
			'return' => 'post_object'
		]
	);

Now you can see that we are querying specifically for trigger posts, so you can eliminate the conditional block for get_post_type that follows a few lines below.

The instructions and the code example above can also be used as a template to resolve the warnings mentioned on the following lines:
197
213
235
251

Finally, look at my-account-documentation.php starting at line 39:

$args = array(
			'post_type'  => 'kb-article',
			'meta_query' => array(
				array(
					'key'     => '_wpcf_belongs_product_id',
					'value'   => $productid,
					'compare' => '=',
				),
			),
			'post__not_in' => array($productid),
		);
		$child_posts = get_posts($args);

Again, you can use the toolset_get_related_posts API to retrieve these child posts:

$child_posts = toolset_get_related_posts(
			// get posts related to this one
			$productid,

			// legacy relationship array syntax
			array( 'product', 'kb-article'),

			// additional arguments
			[
				'query_by_role' => 'parent',
				'limit' => 10000,
				'offset' => 0,
				'args' => [],
				'role_to_return' => 'other',
				'return' => 'post_object'
			]
		);

I recommend making these modifications and testing on a staging environment before attempting to migrate the live site. Let me know if you have questions about the code updates and I can try to clarify.

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