Unable to get relationship to work with View

Support MB Relationships Unable to get relationship to work with ViewResolved

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #41547
    davidvanvodavidvanvo
    Participant

    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 ASmbr_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 BYmbr_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 %}
    
    #41556
    PeterPeter
    Moderator

    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

    #41558
    davidvanvodavidvanvo
    Participant

    It actually works fine when not using relations. But, I did try this and same result.

    #41571
    PeterPeter
    Moderator

    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.

    #41573
    davidvanvodavidvanvo
    Participant

    I've posted the screenshot here

    I've also tried from and to with same results.

    #41577
    PeterPeter
    Moderator

    Hello,

    I do not see the relationship ID in the screenshot, can you please take a full screenshot?

    #41580
    davidvanvodavidvanvo
    Participant

    yep. full screenshot here

    #41582
    PeterPeter
    Moderator

    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.

    #41583
    PeterPeter
    Moderator

    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.

    #41584
    davidvanvodavidvanvo
    Participant

    Thanks for that. Looks like it's FacetWP.

    #41585
    davidvanvodavidvanvo
    Participant

    There is a "Strict query detection" that can be turned on. This appears to fix the problem.

    Thanks!

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.