Home › Forums › ACF PRO › Exclude Current Post in Foreach › Reply To: Exclude Current Post in Foreach
Hello John
Thank you to reply it
Now my code is clear and i think this more clean then first
<?php
$mainbrandquery = get_field('product_offers_relationship');
// go related MAIN POSTS and start searching query in mainbrands
if($mainbrandquery): ?>
<ul class="list-unstyled">
<?php foreach( $mainbrandquery as $m) : ?>
<?php
$mainbrandsowner = get_field('owner_facts_post_relationship', $m->ID);
// go and search owner posts at mainbrand
?>
<li>
<?php foreach( $mainbrandsowner as $o) : ?>
<?php
$mainbrands = get_field('owner_facts_post_relationship', $o->ID);
// we are in owner and check how many other main brands assigned in this field
?>
<?php foreach( $mainbrands as $m) : ?>
<?php
$subproducts = get_field('product_offers_relationship', $m->ID);
// find sub products at each assigned mainbrands and start listing them on front end
?>
<?php foreach( $subproducts as $s) : ?>
<!-- NOW SUB POSTS OF MAINBRANDS WITH SAME OWNERS ARE LISTING HERE -->
<!-- system need to show SUB PRODUCTS of MAINBRANDS which assigned with same owner exclude current post -->
<!--This is listing like
- Product a
- product b
- product c ( c is also current post )
-->
<p><?php echo get_the_title($s->ID); ?></p>
<p><?php echo get_the_permalink($s->ID); ?></p>
<!-- NOW SUB POSTS OF MAINBRANDS WITH SAME OWNERS ARE LISTING HERE -->
<?php endforeach; ?>
<?php endforeach; ?>
<?php endforeach; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
at this point, still I’m trying to find solution to exclude it current post in list when i will find the solution, i will share it or i have to wait someone to help this situation 🙂
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.