Support Forum
Support › MB Relationships › Gutenberg Block with Relation does not work anymore
Hi,
i have a MetBox Gutenberg Block with the following Code:
<?php
$connected = new WP_Query( [
'relationship' => [
'id' => 'kontakte-auf-seiten',
'to' => get_the_ID(), // You can pass object ID or full object
],
'nopaging' => true,
] );
while ( $connected->have_posts() ) : $connected->the_post();
?>
<div class="wrapper">
<div class="person">
<figure><?php echo get_the_post_thumbnail( $page->ID, 'kontaktpersonen' ); ?></figure>
<div class="person-innercontent">
<!-- <h5><?php $value = rwmb_the_value( 'anrede' ); ?></h5>-->
<h3><?php the_title(); ?></h3>
<p>Tel.: <a href="tel:<?php $telefon = rwmb_meta( 'telefon' ); echo $telefon; ?>"><?php $telefon = rwmb_meta( 'telefon' ); echo $telefon; ?></a><br />
Fax: <?php $fax = rwmb_meta( 'fax' ); echo $fax; ?></p>
<p class="m-ail kontakt-mal"><a href="mailto:<?php $email = rwmb_meta( 'email' ); echo $email; ?>"><?php $email = rwmb_meta( 'email' ); echo $email; ?></a> </p>
</div>
<a href="mailto:<?php $email = rwmb_meta( 'email' ); echo $email; ?>" class="kontakt-button">Kontaktieren</a>
</div>
</div>
<?php
endwhile;
wp_reset_postdata();
?>
The in a page, where i add the Block, i select the relatiosnhip in the Sidebar, and the Blcok renders the Related Post Type elements. S´This used to work, But now it does nto show the renderigns anymore…
Do you have an idea, why that could be?
Sorry for my sloppy typing abovw…
This used to work – but now it does not show the related items anymore…
Hello Marius,
In the template file or callback function, please use the variable $post_id
to get the current post ID where you use the custom block. Please read more on the documentation https://docs.metabox.io/extensions/mb-blocks/#render_callback
For example:
'relationship' => [
'id' => 'kontakte-auf-seiten',
'to' => $post_id, // You can pass object ID or full object
],
Then pass the page ID variable to the third parameter of the helper function
rwmb_meta( 'fax', '', $page->ID )
Let me know how it goes.
Hello Peter,
thanks for your feedback.
Unfortunatly no success…
I rewrote it to this:
<?php
$post_id = get_the_ID();
$connected = new WP_Query( [
'relationship' => [
'id' => 'kontakte-auf-seiten',
'to' => $post_id,
],
'nopaging' => true,
] );
while ( $connected->have_posts() ) : $connected->the_post();
?>
<div class="wrapper">
<div class="person">
<figure><?php echo get_the_post_thumbnail( $page->ID, 'kontaktpersonen' ); ?></figure>
<div class="innercontent">
<!-- <h5><?php $value = rwmb_meta( 'anrede', '', $post_id ); ?></h5>-->
<h3><?php the_title(); ?></h3>
<p>Tel.: <a href="tel:<?php echo rwmb_meta( 'telefon', '', $post_id ); ?>"><?php echo rwmb_meta( 'telefon', '', $post_id ); ?></a><br />
Fax: <?php echo rwmb_meta( 'fax', '', $post_id ); ?></p>
<p class="m-ail kontakt-mal"><a href="mailto:<?php echo rwmb_meta( 'email', '', $post_id ); ?>"><?php echo rwmb_meta( 'email', '', $post_id ); ?></a> </p>
</div>
<a href="mailto:<?php echo rwmb_meta( 'email', '', $post_id ); ?>" class="kontakt-button">Kontaktieren</a>
</div>
</div>
<?php
endwhile;
wp_reset_postdata();
?>
Additional Question: Is this related to PHP 8? Because i did the switch a few days ago and maybe since then it it not workign anymore…
And i build it last year, with the MB Blocks Plugin
Hello,
If you view the block in the admin area, please remove this line in your code
$post_id = get_the_ID();
If you view the block in the frontend, you can keep it.
If it still does not work, please share your site credentials (should be a staging site so I can make some tests there) to the contact form https://metabox.io/contact/, and let me know where I can find your code. I will take a closer look.
Hi Peter,
Unfortunately, this does not help.
Have you received my email from the contact form last week?
I did send you Credentials to the staging Website.
Thanks in advance
Marius
Hello,
I have not received any email from you. Can you please resend it?
Just send it via your contactform again.
With Subject: Gutenberg Block with Relation does not work anymore
Hi Peter,
Did it reach you this time?
Thanks in advance
Marius
Hello,
I'm sorry about that, there was an issue with our ticket system. Can you please send the info again?
Just send it again.
Thankfully, last time (2nd try), i saved the email-text 😉