Broken database queries.
Support › MB Relationships › Broken database queries.Resolved
- This topic has 8 replies, 2 voices, and was last updated 1 year, 2 months ago by
Topher DeRosia.
-
AuthorPosts
-
February 17, 2024 at 9:00 PM #44596
Topher DeRosia
ParticipantI 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?
February 17, 2024 at 9:07 PM #44597Topher DeRosia
ParticipantThis 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.
February 18, 2024 at 9:24 PM #44604Peter
ModeratorHello 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?
February 19, 2024 at 7:46 AM #44609Topher DeRosia
ParticipantThe 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?
February 19, 2024 at 8:56 PM #44616Peter
ModeratorHello,
>> 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/
February 20, 2024 at 12:37 AM #44619Topher DeRosia
ParticipantI 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.
February 20, 2024 at 8:36 PM #44624Topher DeRosia
ParticipantAny help with this one? I really need to get it fixed.
February 20, 2024 at 8:59 PM #44626Peter
ModeratorHello,
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.February 25, 2024 at 8:24 AM #44657Topher DeRosia
ParticipantClosing 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.
-
AuthorPosts
- You must be logged in to reply to this topic.