Support Forum
Support › MB Relationships › Broken database queries.Resolved
I got this from my host:
There are thousands of failed queries being sent.
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 ')) OR (mbr.to = wp_posts.ID AND mbr.from IN ())))
WHERE 1=1 AND ((wp_pos...' at line 2 for query
SELECT SQL_CALC_FOUND_ROWS wp_posts.* , mbr.from AS mbr_from, mbr.to AS mbr_to, mbr.ID AS mbr_id, CASE WHEN mbr.to = wp_posts.ID THEN mbr.order_from WHEN mbr.from = wp_posts.ID THEN mbr.order_to END AS <code>mbr_order</code>
FROM wp_posts INNER JOIN wp_mb_relationships AS mbr ON (mbr.type = 'reviewed-by' AND ((mbr.from = wp_posts.ID AND mbr.to IN ()) OR (mbr.to = wp_posts.ID AND mbr.from IN ())))
WHERE 1=1 AND ((wp_posts.post_type = 'contributor' AND (wp_posts.post_status = 'publish')))
GROUP BY mbr_from, mbr_to, wp_posts.ID
ORDER BY <code>mbr_order</code> ASC, mbr_id DESC
LIMIT 0, 1
made by require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), include('/themes/kadence/404.php'), get_header, locate_template, load_template, require_once('/themes/kadence/header.php'), wp_head, do_action('wp_head'), WP_Hook->do_action, WP_Hook->apply_filters, iea_load_schema_data, iea_get_contributor_schema, iea_contributor_data, WP_Query->__construct, WP_Query->query, WP_Query->get_posts
When digging further, its coming from this script:
insiders-exclusive-authorship/vendor/meta-box/mb-relationships/inc/query/query.php
I have a plugin I wrote using relationships as well as some other modules. They're all included in the plugin, so I can get you a copy if you need it.
What can we do about this?
This is a function listed in the section calling that stuff.
function iea_contributor_data( $type = 'authored-by' ) {
$connected = new WP_Query(
array(
'relationship' => array(
'id' => esc_attr( $type ),
'from' => get_the_ID(), // You can pass object ID or full object
),
'posts_per_page' => 1,
)
);
return $connected;
}
Should I be limiting it somehow? This should really only run on Posts.
Hello Topher,
If you add the WP Query with relationship parameter to the post template in the theme file without using your custom plugin to show the relationship, does it work?
The problem is that it always works when there's a connection to be had. I think it's returning those errors on all the posts that don't have relationships.
I tried storing the related post object in meta, but it corrupts the data going into the editor.
I thought about storing it in a transient, but that fills up the database fast and makes wp_load_alloptions go too slow.
How can I properly cache these relationships?
Hello,
>> The problem is that it always works when there's a connection to be had.
You can try to check if two objects have a connection, please follow the documentation https://docs.metabox.io/extensions/mb-relationships/#has
If you want to use the cache, please use WordPress object cache https://developer.wordpress.org/reference/classes/wp_object_cache/
I have the ID of the post I'm on, how do I know the ID of the other end, to check?
In other words, I want to know if current post is connected to ANY of the other post type.
Any help with this one? I really need to get it fixed.
Hello,
Please share your site credentials via this contact form https://metabox.io/contact/
and let me know how to see the issue on your site. I will take a look.
Closing this. We didn't really fix the query, I THINK it was erroring because I was trying to detect a connection where there wasn't one. This was causing an IN statement with no IDs, which MariaDB gave an error on, but MySQL did not.
The way I "fixed" it was putting in more tests to make sure it was only looking for a connection on pages that really should have one, and THEN storing the object it got back in meta on the post.
DO NOT fetch this meta in the admin area, catastrophic error loss will occur.