Hello. I’m having some strange results and looking for some guidance. I have a custom post type for real estate properties. Then I have a home page where you can select one property from the post object dropdown. That property then displays on the home page.
On the properties I have a acf text field called ‘tagline’ and I’m trying to get the tagline to display along with the post title and the featured image. Currently I have two properties posted but it will only display the ‘tagline’ text field from one of the properties. If I change my post object choice to the other property, it won’t display this field.
Here’s my code
@php
$post_object = get_field('featured_property');
global $post;
$post = $post_object;
setup_postdata( $post );
@endphp
@if($post_object)
<div class="uk-container hero-container">
<div class="hero-content">
<h1>{{ the_title() }}</h1>
<p class="lead text-white">
{{ get_field('tagline', $post_object->ID) }}
</p>
<a href="{{ the_permalink() }}" class="btn btn-primary" aria-label="Check it out"><div>Check it out</div></a>
</div>
</div>
<img class="lozad" data-src="{{ the_post_thumbnail_url() }}" alt="hero" uk-cover>
{{ wp_reset_postdata() }}
@endif
I tested your code on my end and it works great. Could you please share the JSON or XML export of your field group so I can check your setup?
Also, you can always use the returned post as a post object like this:
<?php $post_object = get_field('kurs_zu_diesem_seminar'); ?>
<h3><a href="<?php echo get_permalink($post_object->ID); ?>"><?php echo $post_object->post_title; ?></a></h3>
I hope this helps. Thanks 🙂