Order by first and last name from custom fields.
<?php
$q = new WP_Query(array(
'category_name' => 'orders',
'meta_query' => array(
'ln' => array(
'key' => 'ln',
),
'fn' => array(
'key' => 'fn',
),
),
'orderby' => array(
'ln' => 'ASC',
'fn' => 'ASC',
),
'posts_per_page' => -1,
));
if ($q->have_posts()) {
echo '<ul>';
while ($q->have_posts()) {
$q->the_post();
$fn = get_post_meta(get_the_ID(), 'fn', true);
$ln = get_post_meta(get_the_ID(), 'ln', true);
printf(
'<li><a href="%s">FN: %s LN: %s</a></li>',
esc_url(get_permalink()),
$fn,
$ln
);
}
echo '</ul>';
wp_reset_postdata();
}
?>
template.php