Error in Code to display relationship data

Support MB Relationships Error in Code to display relationship data

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #40348
    JoeJoe
    Participant

    HI,

    I have written this code, it is semantically correct , but i get an error something about normalizer.php on line 76, here is the code :

    `<?php
    // WP_Query arguments.
    $args = array(
    'no_found_rows' => true,
    'relationship' => [
    'id' => 'opinion-course,opinion-events',
    'from' => get_the_ID(), // You can pass object ID or full object
    ],
    );
    $query = new WP_Query( $args );

    // the Loop
    if ( $query->have_posts() ) {
    while ( $query->have_posts() ) {
    $query->the_post();
    printf( '%s', esc_url( get_permalink() ), esc_html( get_the_title() ) );
    }
    } else {
    // No posts found
    }
    // Restore original Post Data
    wp_reset_postdata();
    ?>'

    here the complete error message : 'Fatal error: Uncaught Error: Call to a member function get_db_field() on null in /home/sites/24b/d/dbb02ed798/public_html/staging/visionaut/wp-content/plugins/meta-box-aio/vendor/meta-box/mb-relationships/inc/query/normalizer.php:76 Stack trace: #0 /home/sites/24b/d/dbb02ed798/public_html/staging/visionaut/wp-content/plugins/meta-box-aio/vendor/meta-box/mb-relationships/inc/query/normalizer.php(37): MBR_Query_Normalizer->normalize_args(Array) #1 /home/sites/24b/d/dbb02ed798/public_html/staging/visionaut/wp-content/plugins/meta-box-aio/vendor/meta-box/mb-relationships/inc/query/post.php(48): MBR_Query_Normalizer->normalize(Array) #2 /home/sites/24b/d/dbb02ed798/public_html/staging/visionaut/wp-includes/class-wp-hook.php(308): MBR_Query_Post->parse_query(Object(WP_Query)) #3 /home/sites/24b/d/dbb02ed798/public_html/staging/visionaut/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters(NULL, Array) #4 /home/sites/24b/d/dbb02ed798/public_html/staging/visionaut/wp-includes/plugin.php(565): WP_Hook->do_action(Array) #5 /h in /home/sites/24b/d/dbb02ed798/public_html/staging/visionaut/wp-content/plugins/meta-box-aio/vendor/meta-box/mb-relationships/inc/query/normalizer.php on line 76'

    #40349
    JoeJoe
    Participant

    the printf line is wrong : it should just be : the_title()

    #40352
    PeterPeter
    Moderator

    Hello Joe,

    The relationship ID only accepts one. For example:

    'id' => 'opinion-course',

    If you want to query my multiple relationships, please read more on the documentation https://docs.metabox.io/extensions/mb-relationships/#query-by-multiple-relationships

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