Home › Forums › General Issues › Order archive based on custom post object metakey value › Reply To: Order archive based on custom post object metakey value
Hi Steve,
You can’t do what you’re asking just by modifying the wp_query with pre_get_posts.. Atleast not by querying artwork.
However, you can instead of directly querying artwork and trying to order those query the artists.
So you would do a custom wp_query for all artists and order them by their lastname like so:
$args = array(
'post_type' => 'artist',
'orderby' => 'meta_value',
'meta_key' => 'surname',
'posts_per_page' => -1
);
Then as you loop through each artist you query their artwork (inside the artist loop).
$artist_ID = get_the_ID();
$artwork_args = array(
'post_type' => 'artwork',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'artist_dropdown',
'value' => $artist_ID,
'compare' => '='
)
)
);
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.