Support

Account

Home Forums Gutenberg Block: Relationship: get_field

Solved

Block: Relationship: get_field

  • Converting some custom fields to blocks. This works super nice!

    Just one thing isn’t, getting fields in from a Relationship field in a block.
    This is my code inside the block. get_field(‘nationaliteit’) isn’t giving any values.
    Any insights?

    	if(get_field('program-highlights')) :
    	
    		$posts = get_field('program-highlights');
    	    global $post;
    	    
    	    if( $posts ): 
    	    
    			foreach( $posts as $post):
    		    	setup_postdata($post);
    		    	
    				if(get_field('nationaliteit')) {
    					echo '<li><a href="'.get_the_permalink().'">'.get_the_title().'</a> /'.get_field('nationaliteit').'</li>';
    				} else {
    					echo '<li><a href="'.get_the_permalink().'">'.get_the_title().'</a></li>';
    				}
    				
    		    endforeach;
    		    
    		    wp_reset_postdata();
    	    	echo '<li><a href="/festival/lineup/">& many more</a></li>';
      	
    	    endif; 
    	else :
    		echo '<li><a href="#">Coming soon</a></li>';
    	endif; 
  • oi… just add the post->ID to get_field does the trick

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Block: Relationship: get_field’ is closed to new replies.