advanced-custom-blocks icon indicating copy to clipboard operation
advanced-custom-blocks copied to clipboard

Block data not being passed to the_content for use on other pages

Open asadrahbar opened this issue 7 years ago • 3 comments

This might be too much to ask, but it was working in v2.0.2 (before block templates were moved out of functions.php and put in the blocks/acf folder).

None of the tab blocks I've seen allow blocks as content, so I made a tabs block that's just a relationship field to select posts or pages for the tab content - basically allows for complex tab content without cluttering the page containing the tabs.

The problem is that blocks created with this plugin are not displayed when pulled into the tab (core and atomic blocks work fine). The markup from blocks/acf is there, but none of the data from the custom fields is pulled in. This is true of both my post grid block and icons block (one uses a loop, the other doesn't).

Tab block template:

$tabs = get_field('tab_content');

	if( $tabs ): ?>
	<div class="tabs">
	<ul>
	<?php foreach( $tabs as $tab ): ?>
	    <li><?php echo '<a href="#' . $tab->post_name . '">' . get_the_title( $tab->ID ) . '</a>'; </li>
	<?php endforeach; ?>
	</ul>
		<?php foreach( $tabs as $tab ): ?>
	    <div id="<?php echo $tab->post_name; ?>">
	    	<?php $tabcontent = apply_filters('the_content', $tab->post_content);
	echo $tabcontent; ?>
	    </div>
	<?php endforeach; ?>
		</div><!-- /tabs -->
<?php endif; 

Icons block template (repeater field):

if( have_rows('ma_icons') ): 
	$ma_iconcount = count(get_field('ma_icons')); 
	echo '<div class="wp-block-columns alignwide has-' . $ma_iconcount . '-columns">';
	while( have_rows('ma_icons') ): the_row(); 

		$link = get_sub_field('icon_link');
		$icon = get_sub_field('icon');
		$icon_hover = get_sub_field('icon_hover');

		echo '<div class="wp-block-column">'; ?>

			<a class="icon center" href="<?php 
			if( $link ) { echo $link['url']; } else { echo ' '; } ?>" target="<?php echo $link['target']; ?>">
		<span class="icon-img"><img src="<? echo $icon; ?>" alt="" /><img src="<? echo $icon_hover; ?>" alt="" /></span>
		<?php echo $link['title']; ?>
    </a>
	<?php echo '</div>'; endwhile; echo '</div>';
	endif;

Post grid block template:

if (get_field('num_posts')) { $num_posts = get_field('num_posts'); }
		else {$num_posts = 4;}
	$posts_cat_array = get_field('posts_cat'); 	
		$catstring = '';
		if ($posts_cat_array) {
		foreach ($posts_cat_array as $value) :
   			$catstring .= $value->term_id . ", ";
		endforeach;
		}
	$showimg = get_field('show_featured_image');
	$showdate = get_field('show_date');
	$contentdisp = get_field('content_display');
	$linktxt = get_field('link_text');
	$linktype = get_field('link_type');
	?>
	<div class="ab-block-post-grid alignwide"><div class="ab-post-grid-items is-grid columns-2">
		<?php $postsloop = new WP_Query( array( 'post_type' => 'post', 'category__and' => array( $catstring ), 'posts_per_page' => $num_posts ) ); 
if ( $postsloop->have_posts() ) { while ( $postsloop->have_posts() ) : $postsloop->the_post();
	echo '<article';
	if ( has_post_thumbnail() ) { echo ' class="has-thumb"'; }
	echo '>';
		if ( $showimg && has_post_thumbnail() ) { ?>
		<div class="ab-block-post-grid-image">
			<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
        	<?php the_post_thumbnail(); ?>
    		</a>
		</div>
		<?php } ?>
		<div class="ab-block-post-grid-text">
			<h2 class="ab-block-post-grid-title"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
				<?php if ($showdate) { atomic_blocks_post_byline(); } 
			if ($contentdisp == 'excerpt') { ?>			
				<div class="ab-block-post-grid-excerpt"><?php the_excerpt(); ?></div>
			<?php } else { ?>
				<div class="ab-block-post-grid-content"><?php the_content(); ?></div>
			<?php } if ($linktxt) { echo '<p class="right">';
				if ($linktype == 'text') { ?>
					<a href="<?php the_permalink(); ?>" rel="bookmark"><?php echo $linktxt; ?></a>
				<?php } else { ?>
					<a href="<?php the_permalink(); ?>" class="ab-button ab-button-shape-circular ab-button-size-small" style="color:#ffffff;background-color:#c44d3b"><?php echo $linktxt; ?></a>
				<?php } echo '</p>'; } ?>
		</div>
		
	<?php echo '</article>';
  endwhile; } wp_reset_query();
	echo '</div></div>';

asadrahbar avatar Oct 06 '18 05:10 asadrahbar

To be more clear, I place my post grid block on a post along with core blocks and others from atomic blocks. I then create a new page and select the post in the tabs block relationship field. The new page displays all content from the post except for my post grid block (or any others created with ACB). However, any content or markup in the block template that's not dependent on custom fields is displayed in the tab on the new page.

I thought I might need to use: get_field('tab_content', $otherpage) (or something similar in the other blocks) but I'm not sure how to set the $otherpage ID.

asadrahbar avatar Oct 06 '18 05:10 asadrahbar

@asadrahbar Make sure the name of the PHP templates are correct.

Also, can you post screenshots of the field group configurations?

rchipka avatar Oct 09 '18 16:10 rchipka

It's just a relationship field returning post object

asadrahbar avatar Oct 23 '18 07:10 asadrahbar