I am having troubles wrapping my brain around this. Perhaps it is easy and I am just overthinking this.
I am using the relationship field to show a list from a custom post type called ‘speaker_info’ on a page. Each of these ‘speaker_info’ post entries has an advance custom field entry for ‘last_name’ and ‘first_name.’
I need to be able to show this list ordered by the custom field ‘last_name’
Currently I just have the default code from the example page, and have tried different queries with no luck.
$posts = get_field('speakers_two');
if( $posts ): ?>
<?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
<?php setup_postdata($post); ?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<span>Custom field: <?php the_field('last_name'); ?></span>
<?php endforeach; ?>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>
Can anyone please help me change this so that I may query the custom post types by the last_name custom field.