Support Forum
Support › MB Relationships › Database Error on Relationships after update to latest MetaBox AIO and WP 5.5.1
Hello,
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 AS mbr_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 BY mbr_hotel_to_city_to
, wp_posts.ID ORDER BY mbr.order_to
Hi,
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.
Hello, I shared the details for the staging site through the contact form as requested. Please confirm you received the data.
Thanks! 🙂
Mauro.
Oh 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.php
Hello Long,
Any update on the database error?
Thank you for looking into this.
Mauro.
Hi,
I've got the site information and log in to the admin dashboard. I will inform you if have any clue.
Hello 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;
}
Hi,
Thank you for your feedback.
I've informed the development team to check this case and get back to you later.
Hi !
I ran into the same error.
Have you been able to look into it ?
Thank you for your support !
Have a good day,
Johann
For 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 AS mbr_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 BY mbr_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
Hi 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 code
add_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