Unable to get relationship to work with View
Support › MB Relationships › Unable to get relationship to work with ViewResolved
- This topic has 10 replies, 2 voices, and was last updated 1 year, 12 months ago by
davidvanvo.
-
AuthorPosts
-
April 20, 2023 at 3:41 AM #41547
davidvanvo
ParticipantI 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 %}
April 20, 2023 at 5:58 PM #41556Peter
ModeratorHello,
I think the CPT slug should be in lower case like
film
orfilmmaker
, please follow the documentation https://docs.metabox.io/extensions/mb-custom-post-type/#post-type-settingsApril 20, 2023 at 7:05 PM #41558davidvanvo
ParticipantIt actually works fine when not using relations. But, I did try this and same result.
April 20, 2023 at 11:38 PM #41571Peter
ModeratorHello,
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 parameterfrom
toto
and add a specific post ID instead offilmmaker.ID
to see how it works.April 21, 2023 at 3:01 AM #41573davidvanvo
ParticipantI've posted the screenshot here
I've also tried
from
andto
with same results.April 21, 2023 at 6:28 PM #41577Peter
ModeratorHello,
I do not see the relationship ID in the screenshot, can you please take a full screenshot?
April 21, 2023 at 8:57 PM #41580davidvanvo
Participantyep. full screenshot here
April 21, 2023 at 11:13 PM #41582Peter
ModeratorHmm, 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.April 22, 2023 at 8:57 AM #41583Peter
ModeratorHello,
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.
April 22, 2023 at 9:02 AM #41584davidvanvo
ParticipantThanks for that. Looks like it's FacetWP.
April 22, 2023 at 9:04 AM #41585davidvanvo
ParticipantThere is a "Strict query detection" that can be turned on. This appears to fix the problem.
Thanks!
-
AuthorPosts
- You must be logged in to reply to this topic.