Skip Navigation

[Resolved] Can't connect posts via Relationships — PHP errors

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
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: Africa/Casablanca (GMT+01:00)

This topic contains 2 replies, has 2 voices.

Last updated by nicholasG-2 4 years, 4 months ago.

Assisted by: Jamal.

Author
Posts
#1782105

I am trying to:
Link 2 custom post types with an M2M relationship.

I have tried with all other plugins deactivated and the TwentyTwenty theme -- no luck. Prior to this, the site had never used Toolset before. The site I'm referencing is a staging clone of the live site I created for the purposes of this test.

I am able to create the post relationship, and to create new posts in both post types. When trying to connect posts via the Edit screen OR by trying to manually import and create relationships using my own PHP, I get a message in red saying "There has been an error, please try again later." Originally, I was trying to import data from a CSV to populate 2 custom post types (which I've done successfully before on another site on an identical hosting environment) and had thought my import code was the cause, but creating new post types and trying to connect them "normally" from the admin pages produced the same errors.

Thanks very much for your help!

The following PHP errors fill my WP debug log (I removed a couple of `code` tags within the actual error log because it kept borking the formatting here, apologies):
--------------------------------------------
[php]
[19-Sep-2020 03:01:21 UTC] PHP Notice: register_rest_route was called incorrectly. The REST API route definition for toolset-views/v1/views/(?P<id>\d+).* is missing the required permission_callback argument. For REST API routes that are intended to be public, use __return_true as the permission callback. Please see Debugging in WordPress for more information. (This message was added in version 5.5.0.) in /var/www/html/wp-includes/functions.php on line 5225
[19-Sep-2020 03:01:21 UTC] PHP Notice: register_rest_route was called incorrectly. The REST API route definition for toolset/v2/search-posts is missing the required permission_callback argument. For REST API routes that are intended to be public, use __return_true as the permission callback. Please see Debugging in WordPress for more information. (This message was added in version 5.5.0.) in /var/www/html/wp-includes/functions.php on line 5225
[19-Sep-2020 03:01:21 UTC] PHP Notice: register_rest_route was called incorrectly. The REST API route definition for toolset-dynamic-sources/v1/dynamic-sources is missing the required permission_callback argument. For REST API routes that are intended to be public, use __return_true as the permission callback. Please see Debugging in WordPress for more information. (This message was added in version 5.5.0.) in /var/www/html/wp-includes/functions.php on line 5225
[19-Sep-2020 03:01:21 UTC] PHP Notice: register_taxonomy was called incorrectly. The "type" taxonomy "name" property (type) conflicts with an existing property on the REST API Posts Controller. Specify a custom "rest_base" when registering the taxonomy to avoid this error. Please see Debugging in WordPress for more information. (This message was added in version 5.4.0.) in /var/www/html/wp-includes/functions.php on line 5225
[19-Sep-2020 03:02:42 UTC] PHP Deprecated: media_buttons_context is deprecated since version 3.5.0! Use media_buttons instead. in /var/www/html/wp-includes/functions.php on line 5148
[19-Sep-2020 03:02:54 UTC] PHP Fatal error: Uncaught Error: Class 'Toolset_Association_Query_Condition_Element_Status' not found in /var/www/html/wp-content/plugins/types/application/viewmodels/related_content_post.php:174
Stack trace:
#0 /var/www/html/wp-content/plugins/types/application/viewmodels/related_content_post.php(188): Types_Viewmodel_Related_Content_Post->get_related_content_from_uid(2360)
#1 /var/www/html/wp-content/plugins/types/application/controllers/ajax/handler/related_content_action.php(532): Types_Viewmodel_Related_Content_Post->get_related_content_from_uid_array(2360)
#2 /var/www/html/wp-content/plugins/types/application/controllers/ajax/handler/related_content_action.php(309): Types_Ajax_Handler_Related_Content_Action->insert_connect('insert')
#3 /var/www/html/wp-content/plugins/toolset-blocks/vendor/toolset/toolset-common/inc/toolset.ajax.class.php(264): Types_Ajax_Handler_Related_Content_Action->process_call(Array)
#4 /var/www/html/wp-includes/class-wp-hook.php(287): Toolset_Ajax->__call('callback_relate...', Array)
#5 /var/www/ in /var/www/html/wp-content/plugins/types/application/viewmodels/related_content_post.php on line 174

#1782335

Hello and thank you for contacting the Toolset support.

This is the error that is causing your code to crash:

[19-Sep-2020 03:02:54 UTC] PHP Fatal error: Uncaught Error: Class 'Toolset_Association_Query_Condition_Element_Status' not found in /var/www/html/wp-content/plugins/types/application/viewmodels/related_content_post.php:174
Stack trace:
#0 /var/www/html/wp-content/plugins/types/application/viewmodels/related_content_post.php(188): Types_Viewmodel_Related_Content_Post->get_related_content_from_uid(2360)
#1 /var/www/html/wp-content/plugins/types/application/controllers/ajax/handler/related_content_action.php(532): Types_Viewmodel_Related_Content_Post->get_related_content_from_uid_array(2360)
#2 /var/www/html/wp-content/plugins/types/application/controllers/ajax/handler/related_content_action.php(309): Types_Ajax_Handler_Related_Content_Action->insert_connect('insert')
#3 /var/www/html/wp-content/plugins/toolset-blocks/vendor/toolset/toolset-common/inc/toolset.ajax.class.php(264): Types_Ajax_Handler_Related_Content_Action->process_call(Array)
#4 /var/www/html/wp-includes/class-wp-hook.php(287): Toolset_Ajax->__call('callback_relate...', Array)
#5 /var/www/ in /var/www/html/wp-content/plugins/types/application/viewmodels/related_content_post.php on line 174

The other lines are just notices and should not break your code.

From what I can see, I suspect that you have incomplete plugins(install not complete) or that you have different versions that what is expected.
I'll suggest doing the following:
- Deactivate and remove all Toolset plugins.
- Reinstall and activate the latest version of Types plugin, manually.
- Go to Toolset->Relationships and run the migration wizard(latest version of types has changed the database model a little).
- Make sure that the relationship between your posts is created in Toolset->Relationships.
- Run your code again.

If this does not help, please share the part of your code that is using our function toolset_connect_posts so we can review it.
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts

#1784435

Man, do I feel silly after all that PHP debugging that it was just an incomplete installation -- reinstalling the plugins did the trick. It's always the easy stuff, right?

Thank you!