Home › Forums › Front-end Issues › Sorting in drag and drop relation columns › Reply To: Sorting in drag and drop relation columns
Hi @arakesh
For this kind of case, you need to check if the posts in the loop are discontinued or not. You can do it by using the true/false field in the posts you added to the relationship field. After that, you can put the discontinued posts in a variable and then print it later. It should be something like this:
$the_posts = get_field('relationship_field_name');
// Create a variable to contain the discontinued posts
$discontinued_posts = array();
if( $posts ): ?>
<ul>
<?php foreach( $the_posts as $post): // variable must be called $post (IMPORTANT) ?>
<?php setup_postdata($post); ?>
// Check if the posts is discontinued or not
if( get_field('discontinued_field_name') ){
// Put it in the array for later use.
$discontinued_posts[] = $post;
continue;
}
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<span>Custom field from $post: <?php the_field('author'); ?></span>
</li>
<?php endforeach; ?>
</ul>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>
<?php
// Now we print the discontinued posts
if( $discontinued_posts ): ?>
<ul>
<?php foreach( $discontinued_posts as $post): // variable must be called $post (IMPORTANT) ?>
<?php setup_postdata($post); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<span>Custom field from $post: <?php the_field('author'); ?></span>
</li>
<?php endforeach; ?>
</ul>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>
I hope this helps 🙂
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!
🤔 Curious about the ACF user experience? So are we! Help guide the evolution of ACF by taking part in our first ever Annual Survey and guarantee you’re represented in the results. https://t.co/0cgr9ZFOJ5
— Advanced Custom Fields (@wp_acf) May 8, 2023
© 2023 Advanced Custom Fields.
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.