Database Error on Relationships after update to latest MetaBox AIO and WP 5.5.1
Support › MB Relationships › Database Error on Relationships after update to latest MetaBox AIO and WP 5.5.1
- This topic has 10 replies, 5 voices, and was last updated 3 years, 7 months ago by
RJ Laan.
-
AuthorPosts
-
October 17, 2020 at 3:32 PM #22434
Mauro
ParticipantHello,
On all my relationships I get this error, with no change on my code that worked fine before. This is not limited to this relationship, it happens on all of them. Other then the error, the query results are returned correctly and shown on my pages so I'm assuming there is one query fired per relationship that messes things up. Can you help troubleshooting this?
I'm assuming the issue is at "AND mbr.to IN ()".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 ')) WHERE 1=1 AND wp_posts.post_type IN ('post', 'page', 'attachment', 'itinera' at line 1]
SELECT wp_posts.ID , mbr.to ASmbr_hotel_to_city_to
FROM wp_posts INNER JOIN wp_mb_relationships AS mbr ON (mbr.from = wp_posts.ID AND mbr.type = 'hotel_to_city' AND mbr.to IN ()) WHERE 1=1 AND wp_posts.post_type IN ('post', 'page', 'attachment', 'itinerary', 'top_activity', 'suggested_hotel', 'restaurant', 'city', 'shopping', 'room', 'hotel_activity', 'hotel_service', 'hotel', 'booking') AND (wp_posts.post_status = 'publish' OR wp_posts.post_author = 2 AND wp_posts.post_status = 'private') GROUP BYmbr_hotel_to_city_to
, wp_posts.ID ORDER BY mbr.order_toOctober 18, 2020 at 3:15 PM #22444Long Nguyen
ModeratorHi,
Please follow this guide to know how to create the staging site https://www.wpbeginner.com/wp-tutorials/how-to-create-staging-environment-for-a-wordpress-site/.
Then share the credentials (Admin site and FTP account) via this form https://metabox.io/contact/ and let me know where the code stored, I will help you to debug this case.
October 18, 2020 at 10:32 PM #22448Mauro
ParticipantHello, I shared the details for the staging site through the contact form as requested. Please confirm you received the data.
Thanks! 🙂
Mauro.October 18, 2020 at 10:36 PM #22449Mauro
ParticipantOh almost forgot! The code that defines relationships is in:
wp-content/plugins/mundana-itineraries/classes/MundanaItineraries_MetaBoxes.php on line 258 (function register_relationships).The code that retrieves data is in the same directory, in the file MundanaItineraries.php on line 495 (method get_related_to) and 527 (method get_related_from).
In the theme this is used in several places, here is an example:
wp-content/themes/mundana/template-parts/content-hotel.phpOctober 22, 2020 at 1:39 PM #22527Mauro
ParticipantHello Long,
Any update on the database error?
Thank you for looking into this.
Mauro.October 22, 2020 at 2:55 PM #22528Long Nguyen
ModeratorHi,
I've got the site information and log in to the admin dashboard. I will inform you if have any clue.
June 8, 2021 at 4:10 PM #28762Mauro
ParticipantHello there, this is still an issue. Here are some more details shared by a fellow developer:
PHP Notice: Undefined index: to in /home/XYZ.cloudwaysapps.com/XYZ/public_html/wp-content/plugins/meta-box-aio/vendor/meta-box/mb-relationships/inc/query/normalizer.php on line 82
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...
/** * Normalizes single relationship query arguments. * * @param array $args Query arguments. */ protected function normalize_args( $args ) { $direction = isset( $args['from'] ) ? 'from' : 'to'; $relationship = $this->factory->get( $args['id'] ); $args['id_field'] = $relationship->get_db_field( $direction ); $args['direction'] = $direction; $args['items'] = $this->get_ids( $args[ $direction ], $args['id_field'] ); $args['reciprocal'] = $relationship->reciprocal; unset( $args[ $direction ] ); return $args; }
Sometimes the $args array doesn’t have a ‘to’ key. That’s where the php warning comes from. It's possible to fix the php warning by verifying if the ‘to’ key exists. If it’s missing, you can create it manually. This solution is not the best one because it fixes the PHP warning but it doesn’t fix the database error.
/** * Normalizes single relationship query arguments. * * @param array $args Query arguments. */ protected function normalize_args( $args ) { $direction = isset( $args['from'] ) ? 'from' : 'to'; $relationship = $this->factory->get( $args['id'] ); $args['id_field'] = $relationship->get_db_field( $direction ); $args['direction'] = $direction; if(!isset($args['to'])) { $args['to'] = null; } $args['items'] = $this->get_ids( $args[ $direction ], $args['id_field'] ); $args['reciprocal'] = $relationship->reciprocal; unset( $args[ $direction ] ); return $args; }
June 9, 2021 at 9:22 AM #28779Long Nguyen
ModeratorHi,
Thank you for your feedback.
I've informed the development team to check this case and get back to you later.
June 15, 2021 at 3:57 PM #28908Cereal Concept
ParticipantHi !
I ran into the same error.
Have you been able to look into it ?
Thank you for your support !Have a good day,
JohannJuly 12, 2021 at 10:23 AM #29433Prabakaran Shankar
ParticipantFor me also, same error.
So, I have disabled the render function. Even after it shows the error.Error Details:
[12-Jul-2021 02:45:57 UTC] 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 ')) WHERE 1=1 AND wp_1p_posts.post_type = 'job' AND ((wp_1p_posts.post_statu...' at line 1 for query SELECT wp_1p_posts.* , mbr.to ASmbr_69_to
FROM wp_1p_posts INNER JOIN wp_1p_mb_relationships AS mbr ON (mbr.from = wp_1p_posts.ID AND mbr.type = '69' AND mbr.to IN ()) WHERE 1=1 AND wp_1p_posts.post_type = 'job' AND ((wp_1p_posts.post_status = 'publish')) GROUP BYmbr_69_to
, wp_1p_posts.ID ORDER BY wp_1p_posts.post_date DESC LIMIT 0, 5 made by require('wp-blog-header.php'), wp, WP->main, WP->parse_request, do_action_ref_array('parse_request'), WP_Hook->do_action, WP_Hook->apply_filters, rest_api_loaded, WP_REST_Server->serve_request, WP_REST_Server->dispatch, WP_REST_Server->respond_to_request, WP_REST_Posts_Controller->get_items, WP_REST_Posts_Controller->prepare_item_for_response, apply_filters('the_content'), WP_Hook->apply_filters, do_shortcode, preg_replace_callback, do_shortcode_tag, MBViewsShortcode->render, MBViewsRenderer->render, MetaBoxDependenciesTwigEnvironment->render, MetaBoxDependenciesTwigTemplateWrapper->render, MetaBoxDependenciesTwigTemplate->render, MetaBoxDependenciesTwigTemplate->display, MetaBoxDependenciesTwigTemplate->displayWithErrorHandling, __TwigTemplate_2410833bb708b9f030d76465809eb5b189484cd32768e47e88d9f2048677ec56->doDisplay, twig_get_attribute, MBViewsTwigProxy->__call, call_user_func_array, get_posts, WP_Query->query, WP_Query->get_posts[12-Jul-2021 02:45:57 UTC] PHP Warning: array_map(): Expected parameter 2 to be an array, null given in /var/web/site/public_html/wp-content/plugins/meta-box-aio/vendor/meta-box/mb-views/src/Renderer.php on line 73
September 30, 2021 at 8:00 PM #31095RJ Laan
ParticipantHi all!
I had a similar problem. In my case I was able to track this down to a conflict with FacetWP.
To avoid this conflict with FacetWP, you can use this snippet of codeadd_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) { if ( $is_main_query ) { if ( ! empty( $query->query['relationship'] ) ) { $is_main_query = false; } } return $is_main_query; }, 10, 2 );
Hope this helps,
Ruud -
AuthorPosts
- You must be logged in to reply to this topic.