Support

Account

Home Forums General Issues Order of Posts Using Relationship Field Reply To: Order of Posts Using Relationship Field

  • Have you tried it using a WP_Query? Like this for instance:

    
    <?php 
    
            $speakers = get_field('speakers_two');
            $query = new WP_Query(array(
                'post_type'     => 'speaker_info',
                'post__in'      => $speakers,
                'meta_key'      => 'last_name',
                'orderby'       => 'meta_value',
                'order'         => 'ASC',
            ));
    
            if ($query->have_posts()) : ?>
                <ul>
                    <?php while($query->have_posts()) :
                    $query->the_post();
                    ?>
                        <li>
                            <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                            <span>Custom field: <?php the_field('last_name'); ?></span>
                        </li>
                    <?php endwhile; ?>
                </ul>
            <?php endif; ?>
    

    Let me know if it works or not, it did the trick for me with a relationship field I wanted to sort.