Home › Forums › General Issues › orderby date picker field in get_terms › Reply To: orderby date picker field in get_terms
Ordering terms in WP is tough. For the moment I’ve gone with the solid plugin,
Custom Taxonomy Order NE. If I have time, I’ll likely pursue something along the lines of what you’ve laid out and update this post with progress and potential workaround for others.
But if you can order your taxonomy with the above plugin it allows you inefficiently get an archive of posts by tax term. You can create a series of WP_Query calls that run through each term. Use get_terms()
to create an array of all tax terms, then run a foreach
over each term. This creates a WP_Query
for each term item that will return all posts for a given term. Code to make this happen:
// Get your terms and put them into an array
$issue_terms = get_terms([
'taxonomy' => 'issues',
'hide_empty' => false,
]);
// Run foreach over each term to setup query and display for posts
foreach ($issue_terms as $issue_term) {
$the_query = new WP_Query( array(
'post_type' => 'post',
'tax_query' => array(
array(
'taxonomy' => 'issues',
'field' => 'slug',
'terms' => array( $issue_term->slug ),
'operator' => 'IN'
)
)
) );
// Run loop over each query
while($the_query->have_posts()) :
$the_query->the_post();
// YOUR TEMPLATE OUTPUT FOR EACH POST
endwhile;
}
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.