Support Forum
Support › MB Relationships › Unable to get relationship to work with ViewResolved
I have a relationship with 2 CPT. Using View, each CPT shows up fine, but when I attempt to get its relation I get a SQL 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_posts.post_type = 'film' AND ((wp_posts.post_status ...' at line 2]
SELECT wp_posts.ID , mbr.to AS
mbr_filmmaker-to-film_toFROM wp_posts INNER JOIN wp_mb_relationships AS mbr ON (mbr.from = wp_posts.ID AND mbr.type = 'filmmaker-to-film' AND mbr.to IN ()) WHERE 1=1 AND wp_posts.post_type = 'film' AND ((wp_posts.post_status = 'publish')) GROUP BY
mbr_filmmaker-to-film_to, wp_posts.ID ORDER BY wp_posts.post_date DESC
The error happens when I try to to get_posts.
{% set filmmaker_args = { post_type: 'Filmmaker', posts_per_page: 10} %}
{% set filmmakers = mb.get_posts( filmmaker_args ) %}
{% for filmmaker in filmmakers %}
<a href="{{ mb.get_the_permalink( filmmaker.ID ) }}">{{ filmmaker.post_title }} and {{ filmmaker.ID }}</a>
{% set film_args = { post_type: 'Film', nopaging: true, relationship: {id: 'filmmaker-to-film', from: filmmaker.ID} } %}
{% set films = mb.get_posts( film_args ) %}
{% endfor %}
Hello,
I think the CPT slug should be in lower case like film
or filmmaker
, please follow the documentation https://docs.metabox.io/extensions/mb-custom-post-type/#post-type-settings
It actually works fine when not using relations. But, I did try this and same result.
Hello,
Please share a screenshot of the relationship settings or generate the PHP code and paste it here, I will check if there is an issue with the settings.
You may try to change the relation parameter from
to to
and add a specific post ID instead of filmmaker.ID
to see how it works.
I've posted the screenshot here
I've also tried from
and to
with same results.
Hello,
I do not see the relationship ID in the screenshot, can you please take a full screenshot?
yep. full screenshot here
Hmm, I do not see any issue with the provided information. Please share your site credentials via this contact form https://metabox.io/contact/
and let me know where I can see the issue on your site.
Hello,
It looks like there is a plugin that modifies the WordPress query. I've deactivated all plugins except Meta Box, MB AIO then the relationship posts display as well on the frontend.
Thanks for that. Looks like it's FacetWP.
There is a "Strict query detection" that can be turned on. This appears to fix the problem.
Thanks!