Hey all!
Another question regarding ACF:
I have this code:
<?php if( $faqtest ): ?>
<?php foreach( $faqtest as $thefaq ): ?>
<h3><?php echo get_the_title( $thefaq->ID ); ?></h3>
|<?php echo get_the_content( $thefaq->ID ); ?>|
<?php endforeach; ?>
</ul>
<?php endif; ?>
For some reason, get_the_content returns nothing even though when I use var_dump and pass the array from:
<?php
$faqtest = get_posts(array(
'post_type' => 'faqs',
'meta_query' => array(
array(
'key' => 'associated_service', // name of custom field
'value' => '"' . get_the_ID() . '"', // matches exactly</code>"123", not just 123. This prevents a match for "1234"
'compare' => 'LIKE'
)
),'posts_per_page' => 25
));
?>
I see the text from the post_content field (the normal WP one, not an ACF field).
Any ideas what’s going wrong here?
Thank you!
D
Other important fact – the function get_the_title works perfectly.
Hi @dinosleadingwebstudio-com
You should just be able to use: <?php the_title(); ?>
and <?php the_content(); ?>
Just ensure you use setup_postdata( $post );
in the loop, for example:
<?php
$faqtest = get_posts(array(
'post_type' => 'faqs',
'posts_per_page' => 25,
'meta_query' => array(
array(
'key' => 'associated_service', // name of custom field
'value' => '"' . get_the_ID() . '"', // matches exactly</code>"123", not just 123. This prevents a match for "1234"
'compare' => 'LIKE'
)
),
));
if ( $faqtest ) {
foreach ( $faqtest as $post ) :
setup_postdata( $post ); ?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_content(); ?>
<?php
endforeach;
wp_reset_postdata();
}
Awesome, @jarvis! Thank you. I didn’t realize but should have that ‘$faqtest’ didn’t hold the rest of the “usual” WP post data…but now…it works perfectly. Thank you sir!