Hi
I am using the Post Object field to add multiple values.
I would like add a number to identify each value.
The idea is to identify if it is value 1, 2 or 3 and have an if statement to display each differently.
Can anyone please help me with this?
Many thanks!
Please provide more information. I can’t figure out what you are trying to accomplish. Maybe give an example of the code you expect to use to display them?
Thanks for your reply John.
I would like to format and style the first 2 values differently from the rest.
So the code would be something along the lines of:
<?php
$featured_posts = get_field('test_post_object');
if( $featured_posts ): ?>
<ul>
<?php foreach( $featured_posts as $post ):
if (value == 1|2){ ?>
<div class="bluebg">
<div class="section-inner">
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_post_thumbnail('medium'); ?>
</div>
</div>
<?php } else { ?>
<div class="section-inner">
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_post_thumbnail('medium'); ?>
</div>
<?php } ?>
<?php endforeach; ?>
<?php endif; ?>
If this isn’t possible, I know I can achieve what I want using the repeater field, but this would be much simpler to use.
Thanks for your help!
There isn’t any way to add a value to the relationship field. Using just the relationship field you could only do this based on the count of how many fields are shown and show the first 3 differently
$count = 0;
foreach ($featured_posts as $post) {
$count++;
if ($count <=3) {
// one of the first 3 posts
} else {
// not one of the first 3 posts
}
}
Thanks so much for your help John.
That will do it!