MB Relationships - Database error for relationship between users_to_posts
Support › MB Relationships › MB Relationships - Database error for relationship between users_to_posts
- This topic has 14 replies, 2 voices, and was last updated 1 year, 4 months ago by
Leerpodium.
-
AuthorPosts
-
December 13, 2023 at 4:00 PM #44078
Leerpodium
ParticipantHello,
I registered a relationship between users and posts.
add_action('mb_relationships_init', function () { MB_Relationships_API::register([ 'id' => 'users_to_posts', 'from' => [ 'object_type' => 'user', 'admin_column' => [ 'title' => 'Posts', ], ], 'to' => [ 'object_type' => 'post', 'post_type' => 'post', 'admin_column' => [ 'title' => 'Users', ], ] ]); });
When I go to the edit post screen I will see two metaboxes instead of one.
After I connect a a user to the post, the connection will be displayed correctly in the Users screen (wp-admin/users.php).
The connection however will not be displayed on the Posts screen (wp-admin/edit.php).
Also I will get the following error on the posts screen:
Got error 'PHP message: WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mbr.order_to' at line 6 for query \n\t\t\t\tSELECT wp_users.ID , mbr.to\n\t\t\t\tFROM wp_users INNER JOIN wp_usermeta ON ( wp_users.ID = wp_usermeta.user_id ) INNER JOIN wp_43_mb_relationships AS mbr ON (mbr.from = wp_users.ID AND mbr.type = 'users_to_posts' AND mbr.to IN (1)) \n\t\t\t\tWHERE 1=1 AND ( \n wp_usermeta.meta_key = 'wp_43_capabilities'\n)\n\t\t\t\tmbr.order_to\n\t\t\t\t\n\t\t\t made by WP_List_Table->display, WP_List_Table->display_rows_or_placeholder, WP_Posts_List_Table->display_rows, WP_Posts_List_Table->_display_rows, WP_Posts_List_Table->single_row, WP_List_Table->single_row_columns, WP_Posts_List_Table->column_default, do_action('manage_post_posts_custom_column'), WP_Hook->do_action, WP_Hook->apply_filters, MBR_Admin_Columns->post_to_column_data, MBR_Admin_Columns->get_column_data, MBR_Admin_Columns->get_user_items, get_users, WP_User_Qu...',
The problem did not occur with earlier version of the MB Relationships plugin.
Also the problem does not occur for relationships between posts.
Also in the changelog for the MB Relationships plugin I cannot find any information about the latest version.Hopefully you can help with this issue.
December 14, 2023 at 3:45 PM #44089Peter
ModeratorHello,
If there are two meta boxes, you should have two relationships in the code or in the builder. Please recheck this and remove one and recheck the error in the post screen also.
December 14, 2023 at 4:06 PM #44090Leerpodium
ParticipantThis is a debug site.
I did not use the builder.
The only relationship that is defined is the one that you see in the code example above.December 15, 2023 at 10:10 AM #44097Peter
ModeratorHello,
Please share your site credentials via this contact form https://metabox.io/contact/
I will take a look.December 15, 2023 at 2:45 PM #44101Leerpodium
ParticipantI don't like sharing credentials unless absolutely necessary.
Have you tried to replicate the issue first? And it did not occur?December 16, 2023 at 11:36 AM #44105Peter
ModeratorHello,
Yes, I test this feature on my demo site and do not see that issue. If you don't like sharing credentials, please create a new WordPress site and add only one relationship code to see how it goes.
December 18, 2023 at 10:45 PM #44132Leerpodium
ParticipantHello,
The only relationship that I register is the one described in the initial ticket.
But I have done some further testing and I suspect it has to do with the php version.
With php 7 the problem occurs.
With php 8 the problem does not occur.Can you confirm this?
December 19, 2023 at 7:07 PM #44140Peter
ModeratorHello,
I'm using PHP 7.4.33 on my demo site and don't see that. Also, according to the documentation, we recommend using PHP 7.4 or greater with Meta Box.
https://docs.metabox.io/installation/December 20, 2023 at 6:08 PM #44145Leerpodium
ParticipantHello,
Ok, in that case it was coincidence that the error occurred only on servers with PHP 8.
I did some further testing on my local host.
I will try to replicate these steps on a live server, so I can give you access to it.On my localhost I have:
PHP: Version 7.4.29
MYSQL: 10.4.24-MariaDBI installed two clean WordPress instances: one single site and one multi-site.
The only plugins that are active are
- Metabox
- MB Relationships
- MB Relationships Debug (plugin that registers the relationship)
The debug plugin only registers one relationship:
add_action('mb_relationships_init', function () { MB_Relationships_API::register([ 'id' => 'users_to_posts', 'from' => [ 'object_type' => 'user', 'admin_column' => [ 'title' => 'Posts', ], ], 'to' => [ 'object_type' => 'post', 'post_type' => 'post', 'admin_column' => [ 'title' => 'Users', ], ] ]); });
On both WordPress installations I get two Metaboxes on the post edit screen:
Also I get the following error message:
WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'mbr.order_to' at line 6 for query \n\t\t\t\tSELECT wp_users.ID , mbr.to\n\t\t\t\tFROM wp_users INNER JOIN wp_usermeta ON ( wp_users.ID = wp_usermeta.user_id ) INNER JOIN wp_2_mb_relationships AS mbr ON (mbr.from = wp_users.ID AND mbr.type = 'users_to_posts' AND mbr.to IN (1)) \n\t\t\t\tWHERE 1=1 AND ( \n wp_usermeta.meta_key = 'wp_2_capabilities'\n)\n\t\t\t\tmbr.order_to\n\t\t\t\t\n\t\t\t made by WP_List_Table->display, WP_List_Table->display_rows_or_placeholder, WP_Posts_List_Table->display_rows, WP_Posts_List_Table->_display_rows, WP_Posts_List_Table->single_row, WP_List_Table->single_row_columns, WP_Posts_List_Table->column_default, do_action('manage_post_posts_custom_column'), WP_Hook->do_action, WP_Hook->apply_filters, MBR_Admin_Columns->post_to_column_data, MBR_Admin_Columns->get_column_data, MBR_Admin_Columns->get_user_items, get_users, WP_User_Query->__construct, WP_User_Query->query, referer: http://localhost/wp-dev-2/mb-relationship-debug/wp-admin/post.php?post=1&action=edit
December 20, 2023 at 6:12 PM #44146Leerpodium
Participantp.s.
I meant to say:
Ok, in that case it was coincidence that the error occurred only on servers with PHP 7 (instead of 8).December 21, 2023 at 9:57 PM #44151Peter
ModeratorHello,
You are correct, I can reproduce the issue 2 meta boxes with two plugins Meta Box and MB Relationships. But not the error message. It works if you use the plugin Meta Box AIO.
I've escalated this issue to the development team to fix it in the next update.Thank you.
December 22, 2023 at 5:14 PM #44156Leerpodium
ParticipantHello,
Ok, good to hear you can reproduce (part of) the issue.
For a second I thought I was going insane 🙂I did some further testing on my local host for the error message.
For the single site installation as well as for the multi-site installation I connected a user to a post and checked the post overview screen in the dashboard.On the single site installation the error message does not occur and the relationship is shown correctly:
On the multi-site installation the error message does occur and the relationship is not shown correctly:
So it seems to be an issue with multi-site installations.
Can you confirm this?December 23, 2023 at 10:44 AM #44164Peter
ModeratorHello,
Unfortunately, I cannot reproduce the error message issue on a fresh installation of a multisite environment, screenshots https://imgur.com/a/AArPx3H
I test with a site from https://instawp.com/
December 28, 2023 at 4:16 PM #44180Leerpodium
ParticipantJust to be sure... which PHP version did you use to create the multisite?
And if by any chance you used PHP 8, could you try again with PHP 7?December 28, 2023 at 5:38 PM #44181Leerpodium
ParticipantNevermind, I tested it myself on https://instawp.com/ with PHP 7.4 and the error did not occur.
I will try to debug some further, but could you please let the developers know of the error message?
Maybe they have an idea what might cause such an error. -
AuthorPosts
- You must be logged in to reply to this topic.