It’ so interesting so – the code below is the reverse relationship query minus the (for lack of better terminology) internal relationship query. This works flawlessly, and finds the parent, without interrupting the current post’s data.
<ul class="package">
<?php
$args = array(
'post_type' => 'page',
'meta_query' => array(array(
'key' => 'package-creator',
'value' => '"' . get_the_ID() . '"',
'compare' => 'LIKE'
)
));
$getmysiblings = new WP_Query($args) ?>
<?php if ($getmysiblings->have_posts()): ?>
<?php while ($getmysiblings-> have_posts()): $getmysiblings->the_post(); ?>
<?php // get the relationship field ?>
THIS IS WHERE THE RELATIONSHIP QUERY SHOULD GO.
<?php // end get relationship field ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else: ?>
<?php endif; ?>
</ul>
I’ve tried using both variations of the relationship query inside of the above marked area – and both ways it works, but corrupts the content of the provided page. (which btw, is retrieving ACF fields not just post content) I’ll keep working on it.
Thanks magicstick – I’ve been playing with using both variations (get_post vs wp_query essentially) i’m going to try something else. I’ll report back with any progress.
Thanks for the input – I tried moving the reset to various points like recommended but it’s still causing the $post content to display instead of the proper page content. So odd.
What’s interesting is that it has something to do with the second query (the query for the contents of the relationship field. If i remove that query then i just get the page info for parent, and the rest of the page loads fine. It’s when i attempt a further query into that page that it messes with the $post data. I feel like the answer is right there… just not sure.
Update for anyone reading this – the inclusion of an
if( !empty($location) ):
wrapper around the markers solves the issue.
found this from another post – Worked like a charm for me.
<?php $posts = get_field('featured_space'); if( $posts ): ?>
<div class="acf-map">
<?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
<?php setup_postdata($post); ?>
<?php $space_address = get_field('space_address', $post->ID); ?>
<div class="marker" data-lat="<?php echo $space_address['lat']; ?>" data-lng="<?php echo $space_address['lng']; ?>">
<h4><?php the_title();?></h4>
<p><?php echo $space_address['address']; ?></p>
</div><!--/.marker-->
<?php endforeach; ?>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
</div><!--/.acf-map-->
<?php endif; ?>
I’m also looking to work this out – IF you come up with something please post it here. I’ll do likewise.
Yep. Same issue here – really busted up my client site. Rolling back fixes it.
Ok I think i sourced the issue – the rules i was giving for where it appears included any pages that were not the homepage… this was causing a gallery population field to appear inside the add and image feature, already inside a gallery. Ultimately causing some sort of failure. (Gallerinception)
Removed the rules, seems to work. May want to look into blocking fields from appearing inside of areas like the “Add Image” dialog boxes etc.
wonderful – thanks so much for the input, i’m gonna give this a shot and report back. Appreciate the help.
bumping this again – anyone having any luck?
Brilliant, thanks for the help here.
Looking for some help on this as well – I’m not having any luck so far. OP, if you were able to find a a method, could you post it up?
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.