I have a grid displaying a custom post type on my WordPress homepage, where I also add a text block div after the second post using a loop counter.
I wanted to display that text block using an ACF field, but the loop only worked if I hard coded the div like this:
<div class="projects-list" id="projects">
<div class="project-item"><?php the_field('intro_text_1'); ?></div>
<?php
$args = array( 'post_type' => 'project', 'posts_per_page' => 60 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
?>
<div class="project-item"><a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail( 'homepage-thumb' ); ?>
<div class="overlay"><div class="caption">
<h2><?php the_title(); ?></h2>
<?php
$terms = get_the_terms($post->ID, 'work_type');
if ($terms) {
$terms = array_map(
function($obj) {
return $obj->name;
},
$terms
);
echo '<div class="project-work-type">(' . implode(', ', $terms) . ')</div>';
}
?>
</div>
</div></div>
</a>
<strong><?php if( $loop->current_post == 2 ) {
echo '<div class="project-item text-box">Pitch Design Union makes websites, books, brands, & custom lettering, some of which are shown here.</div>';
} ?></strong>
<?php endwhile;?>
</div>
I was hoping to put in something like:
<div class="project-item"><?php the_field('intro_text_1'); ?></div>
Is there something I’m missing? Or a workaround?
I may be a little lost as to were you want to put the second bit of code. Are you attempting to put it where you have this:
echo '<div class="project-item text-box">Pitch Design Union makes......
and it is supposed to show the same text as where you have this on the second line of your code
<div class="project-item"><?php the_field('intro_text_1'); ?></div>
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
Are you building WordPress sites with ACF and @BeaverBuilder, and wanted to use your ACF Blocks in both the block editor and Beaver Builder?
— Advanced Custom Fields (@wp_acf) May 10, 2023
The BB team recently added support for using ACF Blocks in Beaver Builder. Check it out 👇https://t.co/UalEIa5aQi
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.