I am using a content-search.php template part to output my search results. The post/page titles and links to those posts/pages are working correctly, but for some reason the the_content()
function is not rendering any HTML. I have tested for errors with debugging on, but nothing is displayed.
Here is my content-search.php template code:
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?php the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ); ?>
</header><!-- .entry-header -->
<div class="entry-content">
// No content from posts or pages is displayed using the_content function
<?php the_content(); ?>
</div><!-- .entry-content -->
<footer class="entry-footer">
<?php flagstaffcounty_entry_footer(); ?>
</footer><!-- .entry-footer -->
</article><!-- #post-<?php the_ID(); ?> -->
Here is the search.php template code:
get_header(); ?>
<div class="content-and-sidebar">
<main class="main">
<?php get_search_form(); ?>
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) :
the_post();
get_template_part( 'template-parts/content', 'search' );
endwhile;
the_posts_navigation();
else :
get_template_part( 'template-parts/content', 'none' );
endif;
?>
</main><!-- main -->
<aside class="sidebar">
<?php get_sidebar(); ?>
</aside><!-- aside -->
</div><!-- .content-and-sidebar -->
<?php get_footer();
The the_content
function is working on all other templates on my site.
Update
Including offending iframe wrapper filter function for reference.
function themename_iframe_wrapper($content) {
if( is_page() ) {
$pattern = '~<iframe.*</iframe>~';
preg_match_all($pattern, $content, $matches);
foreach ($matches[0] as $match) {
$wrappedframe = '<div class="iframe-container">' . $match . '</div>';
$content = str_replace($match, $wrappedframe, $content);
}
return $content;
}
}
add_filter('the_content', 'themename_iframe_wrapper');
Any ideas on what I am missing?
echo get_the_content()
instead ofthe_content()
.. to confirm the latter is the one not echoing the content - and if so, try searching foradd_filter( 'the_content'
,add_filter('the_content'
, etc. in your theme functions file.none
template? Are you sure it's finding posts? If it isn't displaying anything what HTML is it showing instead? Do you mean that the template displays butthe_content
specifically is blank? Normally ifthe_content
displays nothing it's because either the content is blank, or, because you've tried usingthe_content
filter incorrectly elsewherethe_content
and wrap them in aniframe-container
div. This code seems to be conflicting with the output in the search results. I have added it to my original question for reference.if
block. So there should always be areturn
line outside theif
block. (Or move thereturn
to outside that block)