I was having a lot of trouble with this as well, especially with the attached images. Here is what I ended up with:
<?php
$rows = get_field('partners');
if($rows) $i = 0; {
shuffle( $rows );
foreach($rows as $row) {
$i++; if($i==6) break;
$image = $row['partner_logo']; ?>
<li class="partners-list-item desaturate"><img src="<?php echo $image; ?>" alt="" /></li>
<?php } } ?>
I also rolled back to 4.3.8 and it still isn’t working.
Here is what I have so far. I’m able to see all the clients from my custom post type and all the posts attached to clients. However, I want it to only show the posts relating to a particular client. I’m not sure what I’m missing.
The ‘attach_to_client’ is the relationship function to the custom post type of ‘clients’.
<?php
$loop = new WP_Query( array( 'post_type' => 'clients', 'posts_per_page' => 10 ) );
$ids = get_field('attach_to_client', false, false);
$query = new WP_Query(array(
'post_type' => array('research', 'project_brief','persona','task_models', 'user_stories', 'style_guide'),
'posts_per_page' => -1,
'post__in' => $ids,
'post_status' => 'any',
'orderby' => 'modified',
));
?>
<?php if($loop->have_posts()) : ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="postbox-container postbox">
<h3><?php the_title(); ?></h3>
<?php if ($query->have_posts()) : ?>
<ul>
<?php
while($query->have_posts()) :
$query->the_post();
?>
<li><?php the_title(); ?></li>
<?php endwhile; ?>
</ul>
<?php else: ?>
<p>Oops, there are no posts.</p>
<?php endif; ?>
</div>
<?php endwhile; endif; wp_reset_query(); ?>
Is there a way to add a foreach client loop around so that the posts separate out based on which custom post (clients) they are associated with?
The problem was the default values were taking over the inputted values.
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!
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.