Home › Forums › General Issues › Sorting CPT taxonomy terms
I have a CPT (events), a taxonomy (artists) and a custom select field for the artists (active, not active). Now I want to make a list of the artists who are active, permalinked to their taxonomy page. I know I need to use get_terms, but I haven’t figured it out. Sorry if this is a simple one. Thank you.
I’m using the most current version of ACF PRO and the most current version of WordPress. Thank you.
In ACF pro you can now use term meta queries, basically the same as meta_query for posts in the get_terms() arguments. https://developer.wordpress.org/reference/functions/get_terms/, but the new WP documentation sucks. See the meta_query section of WP_Query, it should be set up the same way https://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters. I really hope that the people doing the new documentation put a little more effort into it when they redo this page or we’re all screwed.
Thank you.
So, this is what I ended up with. It works well.
Do you see any issues there? Thanks again.
<?php $terms = get_terms(array( 'taxonomy' => 'artist', 'meta_key' => 'hide_artist', 'meta_value' => 'active' )); ?>
<?php foreach($terms as $term) {$term_link = get_term_link( $term ); echo '<li><a href="' . esc_url( $term_link ) . '">' . $term->name . '</a></li>';} ?>
Look about right to me. If it’s working they it probably is.
This is what I was after. I was using the same codes but the results are not what I expected and upon visiting this thread, I found out that I will need PRO version. So, my question is if I upgrade to pro, the codes are going to work automagically? or I will need to do some adjustments?
It should work. In version 5.5. of ACF it started using term meta instead of options for storing term custom fields. The update process should convert the data in the database. Make sure you follow the upgrade process carefully https://www.advancedcustomfields.com/resources/upgrading-v4-v5/. If you have any problems after the upgrade submit a support ticket https://support.advancedcustomfields.com/new-ticket/
The topic ‘Sorting CPT taxonomy terms’ is closed to new replies.
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.