test MB_Relationships_API::has function

Support MB Relationships test MB_Relationships_API::has functionResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #41821
    Claudio BallarinClaudio Ballarin
    Participant

    Hi,
    in your documentation I find this code:

    $has_connection = MB_Relationships_API::has( $from, $to, $id );
    if ( $has_connection ) {
    echo 'They have a relationship.';
    } else {
    echo 'No, they do not have any relationship.';
    }

    We have metabox.io pro, and we have setup a relation to test (relation is corretly displyed in backend).
    I have tried to insert it (inserting correct IDs in $from, $to, $id) in functions.php but retun a fatal error:

    Fatal error: Uncaught Error: Class 'MB_Relationships_API' not found in .... functions.php

    Where I can test this code? thanks
    Claudio

    #41823
    PeterPeter
    Moderator

    Hello,

    Can you please put the code to the file functions.php with a higher priority (like init hook and priority 99) in the theme folder and check the issue again? It is possible that the code is executed before Meta Box functions run so there is an error Class 'MB_Relationships_API' not found.

    #41824
    Claudio BallarinClaudio Ballarin
    Participant

    Yes, now work, thank you!

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