I am having a really odd issue with a custom query and loop. I’m looping through and displaying CPT posts of team member bios on a ‘Meet the Team’ page. The content for the first post is not being formatted at all; it doesn’t matter what order the posts are in, the first one just gets spit out raw. The really interesting thing is that if I add a conditional testing for the first item, then ‘manually’ format the content, the second item will not be formatted.
I’m callling the query and loop from a shortcode, and running a very basic child BB theme.
My question is: why is this happening and what can I do about it?
Here’s the function I’m using to do the query:
// Generic basic query function
function twc_basic_query( $posts = -1, $post_type = 'teammember', $order_by = 'menu_order' ) {
$args = array(
'post_type' => $post_type,
'post_status' => 'publish',
'orderby' => $order_by,
'order' => 'ASC',
'posts_per_page' => $posts,
);
$results = new WP_query( $args );
return ( $results -> have_posts() ) ? $results : false;
} // / twc_basic_query
Here’s the shortcode:
function twc_team_members() {
ob_start();
$team = twc_basic_query();
$args = array(
'team' => $team,
);
get_template_part( '/includes/module-team-members', null, $args );
return ob_get_clean();
} // / twc_team_members
add_shortcode( ‘teammembers’, ‘twc_team_members’ );
Here’s the Loop:
<?php
$team = $args['team'];
if( $team ):
if( $team -> have_posts() ):
?>
<div class="fl-team-members">
<?php
while( $team -> have_posts() ):
$team -> the_post();
?>
<div class="fl-team-member-wrap">
<div class="fl-team-member-image">
<?php the_post_thumbnail( $post -> ID, 'full' ); ?>
</div>
<div class="fl-team-member-content">
<div class="fl-team-member-meta">
<h2><?php the_title(); ?></h2>
<p><?php echo( get_field( 'team_member_title' ) ); ?></p>
</div><!-- / .fl-team-member-meta -->
<hr />
<div class="fl-team-member-bio">
<?php echo apply_filters( 'the_content', $post -> post_content ); ?>
</div><!-- / .fl-team-member-copy -->
<?php if( $yt_url = get_field( 'youtube_bio_url' ) ): ?>
<div class="fl-team-member-video">
<a class="fl-button js-new-tab" href="<?php echo $yt_url; ?>">Hear from <?php echo( get_field( 'member_first_name' ) ); ?></a>
</div>
<?php endif; ?>
</div><!-- / .fl-team-member-content -->
</div><!-- / .fl-team-member-wrap -->
<?php
endwhile; // / The Loop while
?>
</div><!-- / .fl-team-members -->
<?php
endif; // / The Loop if
endif; // / $team test
wp_reset_postdata();
I used the_content() in my original code, and got the idea to use echo apply_filters( 'the_content', $post -> post_content ); from this question, but it has no effect.
I also tried using echo wpautop( $post -> post_content ); in a conditional targeting the first post, and it adds paragraph tags as expected, but that results in the second post not being formatted.