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.
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.