Insert connected post title for current item in a Query Loop

Support MB Relationships Insert connected post title for current item in a Query LoopResolved

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #40115
    OlivierOlivier
    Participant

    Hi,

    I'm using the awesome GenerateBlocks plugin to create query loops throughout my site, in this case to display a list of events.

    My Event CPT is connected to a Provider CPT via a MB relationship.

    On my list of events, for each event I would like to display the name of the Provider (post title) connected to it.

    I'm not able to control the code of the query directly (GenerateBlocks does it), but here is a code snippet I can use to replace an element from the query into a custom one:

    add_filter( 'render_block', function( $block_content, $block ) {
    
        if ( !is_admin() && ! empty( $block['attrs']['className'] ) && strpos( $block['attrs']['className'], 'licensee-name' ) !== false ) { // CSS class 'licensee-name' to be added to the block where the value should be output
    
    $myreplace1 = 'placeholder'; // Block content should be set to the word 'placeholder'
    
    $myinsert1 = get_post_meta( get_the_ID(), 'event_host'); // custom field value to retrieve
    
            $block_content = str_replace( $myreplace1, $myinsert1 , $block_content );
    
        }
    
     
    
        return $block_content;
    
    }, 10, 2 );

    Is it possible to modify this snippet to retrieve the Provider 1) name and 2) featured image connected to that Event?

    Thank you

    #40121
    PeterPeter
    Moderator

    Hello,

    I'm afraid that this case is beyond our scope of support. We do not support customization for your specific needs. If you have a compatibility case with another plugin, please contact them to get further assistance. Or you can request a custom development here https://metabox.io/contact/

    Please read more about the support policy here https://support.metabox.io/topic/support-policy/

    #40125
    OlivierOlivier
    Participant

    Thanks Peter, but as far as I understand, that function is a normal WordPress function, not specific to GenerateBlocks - or am I wrong?

    I'm not understanding why this code is not working:

    add_filter( 'render_block', function( $block_content, $block ) {
        if ( !is_admin() && ! empty( $block['attrs']['className'] ) && strpos( $block['attrs']['className'], 'licensee-name' ) !== false ) {
    		$myreplace1 = 'placeholder';
    		
    		$hol_licensee_name = MB_Relationships_API::get_connected( [
    		'id'   => 'licensee-events',
    		'to' => get_the_ID(),
    	] );
    					
            $block_content = str_replace( $myreplace1, $hol_licensee_name , $block_content );
     
        }
     
        return $block_content;
    }, 10, 2 );

    Can you help?

    #40132
    PeterPeter
    Moderator

    Hello,

    The function MB_Relationships_API::get_connected() returns an array, you have to use the return value as an array, not a string.

    I recommend contacting an expert developer WordPress to help you accomplish the task. Without a basic knowledge of coding, you might use the wrong code and break your site later.

    Thanks for your understanding and patience.

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