Support

Account

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 🙂