Gutenberg Block with Relation does not work anymore
Support › MB Relationships › Gutenberg Block with Relation does not work anymore
- This topic has 12 replies, 2 voices, and was last updated 2 years, 2 months ago by
Marius.
-
AuthorPosts
-
February 3, 2023 at 4:13 PM #40387
Marius
ParticipantHi,
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?
February 3, 2023 at 10:37 PM #40392Marius
ParticipantSorry for my sloppy typing abovw…
This used to work – but now it does not show the related items anymore…
February 4, 2023 at 12:12 PM #40396Peter
ModeratorHello 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_callbackFor 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.
February 6, 2023 at 6:14 PM #40405Marius
ParticipantHello 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(); ?>
February 6, 2023 at 6:17 PM #40406Marius
ParticipantAdditional 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…
February 6, 2023 at 6:26 PM #40407Marius
ParticipantAnd i build it last year, with the MB Blocks Plugin
February 7, 2023 at 10:07 PM #40432Peter
ModeratorHello,
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.
February 13, 2023 at 11:55 PM #40505Marius
ParticipantHi 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
MariusFebruary 14, 2023 at 10:11 PM #40516Peter
ModeratorHello,
I have not received any email from you. Can you please resend it?
February 15, 2023 at 4:06 PM #40530Marius
ParticipantJust send it via your contactform again.
With Subject: Gutenberg Block with Relation does not work anymore
February 16, 2023 at 8:17 PM #40554Marius
ParticipantHi Peter,
Did it reach you this time?
Thanks in advance
MariusFebruary 17, 2023 at 10:09 PM #40576Peter
ModeratorHello,
I'm sorry about that, there was an issue with our ticket system. Can you please send the info again?
February 22, 2023 at 12:01 AM #40655Marius
ParticipantJust send it again.
Thankfully, last time (2nd try), i saved the email-text 😉
-
AuthorPosts
- You must be logged in to reply to this topic.