(solved) Metabox / Bidirectional Relationships: How to set up the Condition to hide an empty section?

Hello Community,

I build a Custom Post Type “Testimonials” and connect it with bidirectional Relationships in Metabox to a certain page or template. Now I dont know how to setup the Condition to hide when there is no testimonial.

Problem: When I set up the usual conidition, the whole section disappears. I cannot choose Metabox relationships in the conditions field.

Here is my setup:



I learned that I have to use a custom function for an auomated check or set a radio button with MetaBox to hide the testimonial field manually.

I will look into the custom function and update this when I found a solution.

2 Likes

Christoph gave me the solution in the Inner Circle:

I created two new posts and it works. Still having problems with displaying them on my existing custom post types

function post2post() {
    $connected = new WP_Query( [
        'relationship' => [
            'id'   => 'name-of-your-relationship',
            'from' => get_the_ID(), // You can pass object ID or full object
        ],
        'nopaging'     => true,
    ] );
    return $connected->have_posts();
}

Simply paste that function in a new snippet in WPCodeBox or the snippet plugin of your choice.

In Bricks, you can use it via condition:
Dynamic Data
{echo:get-related-post}
!=
blank field

If there is no related post, your section won’t show.

4 Likes