Site logo

Archived topic

Content from local templates not picked up for excerpt

3 replies · Started by Alexander on August 24, 2021

Viewing posts 1–4 of 4

Hello Team,

I am using this code to output a bunch of news postings (CPT) on my homepage.

function as_fp_news_output($atts, $content = null) {
	
	global $post;
	
	extract(shortcode_atts(array(
        'type' => 'news',
		'num'     => '4',
	), $atts));
	
	$args = array(
       'post_type'      => $type,
       'posts_per_page' => $num,
	);
	
	$output = '';
	
	$posts = get_posts($args);
	
	foreach($posts as $post) {
		
		setup_postdata($post);
		
		$output .= '<article class="loop-item box">
                        <div class="fp-news-image">
                            <a href="'. get_the_permalink() .'">'. get_the_post_thumbnail() .'</a>
                        </div>   
                            <h2 class="news-entry-title"><a href="'. get_the_permalink() .'">'. get_the_title() .'</a></h2>
                            <div class="news-excerpt">'. get_the_excerpt() .'</div>
                        
                    </article>';            
                        	
	}
	
	wp_reset_postdata();
	
	return '<div class="content">'. $output .'</div>';
	
}
add_shortcode('fp_news', 'as_fp_news_output');

When I use previously created local templates to construct my news article (the block consists of container - 50/50 grid - containers - text - image), the contents do not seem to display as an excerpt. The only local template that does seem get picked up is a Headline inside a container. All other templates fail.
If I manually create a container and write a paragraph, everything is fine.

Any ideas?
Thank you in advance!

Hi there,

If you're using a Container or Group Block ( or any unspecified nested block ) in your content then its because of this:

https://core.trac.wordpress.org/ticket/47637

TLDR: WP added excerpt_remove_blocks which only considers top level blocks, anything nested inside another block eg. Group or Container gets stripped....

Current workaround is to use a Manual Excerpt.

Thank you very much David!

You're welcome

This archived topic is closed to new replies.