Support

Account

Home Forums Front-end Issues Simple block not displaying Text Field

Solved

Simple block not displaying Text Field

  • I’ve created a simple block that pulls in posts in a CPT archive…

    
    // Register a 'Board Members' block.
    	add_action( 'init', 'my_board_members_block' );
    	function my_board_members_block() {
    		if ( function_exists( 'acf_register_block_type' ) ) {
    			acf_register_block_type(array(
    				'name'				=> 'board/board-members',
    				'title'				=> __( 'Board Members' ),
    				'description'		=> __( 'displays the board members' ),
    				'render_template'	=> 'template-parts/blocks/board/board.php',
    				'category'			=> 'custom',
    				'icon' 				=> 'buddicons-buddypress-logo',
    				'align'				=> 'wide',
    				'enqueue_assets' 	=> function(){
    					wp_enqueue_style( 'board', get_template_directory_uri() . '/template-parts/blocks/board/board-editor-min.css', array(), '1.0.0' );
    				},
    			));
    		}
    	}
    

    The block works great, or at least it did until earlier today. The last thing I done yesterday was to update to the latest version of ACF Pro. – It worked after that yesterday, but not today.

    <?php
    
    /**
     * Board Members Block Template.
     *
     * @param   array $block The block settings and attributes.
     * @param   string $content The block inner HTML (empty).
     * @param   bool $is_preview True during AJAX preview.
     * @param   (int|string) $post_id The post ID this block is saved to.
     */
    
    // Create id attribute allowing for custom "anchor" value.
    $id = 'board-' . $block['id'];
    if ( ! empty( $block['anchor'] ) ) {
    	$id = $block['anchor'];
    }
    
    // Create class attribute allowing for custom "class_name" and "align" values.
    $class_name = 'board-contain';
    if ( ! empty( $block['class_name'] ) ) {
    	$class_name .= ' ' . $block['class_name'];
    }
    
    if ( ! empty( $block['align'] ) ) {
    	$class_name .= ' align' . $block['align'];
    }
    
    if ( $is_preview ) {
    	$class_name .= ' is-admin';
    }
    
    ?>
    
    <div id="<?php echo esc_attr( $id ); ?>" class="<?php echo esc_attr( $class_name ); ?>">
    	<!-- Board LIST -->
    		<div class="grid-x grid-margin-x grid-margin-y align-center" data-equalizer data-equalize-on="medium" data-equalize-by-row="true">
    			<?php
    				query_posts( array(
    					'post_type'			=> 'board',
    					'posts_per_page'	=> '-1',
    					'order'				=> 'ASC',
    				) );
    
    				if ( have_posts() ) :
    					while ( have_posts() ) :
    						the_post();
    			?>
    					<div class="peopleBlock cell small-12 medium-4 large-3">
    						<div class="peopleImage cell">
    							<?php if ( has_post_thumbnail() ) { ?>
    									<?php the_post_thumbnail( 'med-thumb' ); ?>
    							<?php } else { ?>
    								<img src="<?php bloginfo( 'template_directory' ); ?>/assets/images/default.png" alt="<?php echo esc_attr( the_title() ); ?>, <?php the_field( 'role' ); ?>" />
    							<?php } ?>
    						</div>
    						<div class="peopleText text-center" data-equalizer-watch>
    							<h5><?php echo the_title(); ?></h5>
    							<h6><?php the_field('role'); ?></h6>
    							<a href="<?php the_permalink(); ?>">view profile</a>
    						</div>
    					</div>
    			<?php
    				endwhile;
    				endif;
    			?>
    			</div>
    	<!-- END Board LIST -->
    	<?php
    	wp_reset_query();
    	?>
    </div>
    
    <?php
    	wp_reset_postdata();
    ?>
    

    The title, image & link all show and work, but the custom field (‘role’) is not showing. In console theres no errors, just the empty <h6></h6> where the ‘role’ should be.
    I am sure this is something daft that I have missed. Tried doing //vars and echo’ing that, also tried esc_attr( ‘role’ ) etc. but still nothing showing.

  • Resolved…
    Here’s the solution for anyone searching for the same problem:

    <?php
    $role 		= the_field( 'role' );
    $post 		= get_post();
    ?>
    <h6><?php the_field( 'role', $post ); ?></h6>
    
Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Simple block not displaying Text Field’ is closed to new replies.