Home › Forums › General Issues › Sort Custom Post Type by Taxonomy. › Reply To: Sort Custom Post Type by Taxonomy.
$products = get_field('products_in_this_auction', false false);
$categories = get_terms('type_produc', 'orderby=count&order=DESC&hide_empty=1');
foreach( $categories as $category ):
?>
<h3 class="title_pru"><?php echo $category->name; // Prints the cat/taxonomy group title ?></h3>
<?php
$posts = get_posts(array(
'post__in' => $products,
'post_type' => 'myproduct',
'taxonomy' => $category->taxonomy,
'term' => $category->slug,
'nopaging' => true,
));
foreach($posts as $post):
setup_postdata($post);
?>
<div id="post-<?php the_ID(); ?>">
<?php the_title( sprintf( '<p class="title_pru"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></p>' ); ?>
</div><!-- #post-## -->
<?php endforeach; ?>
<?php endforeach; ?>
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!
🚀 ACF & ACF PRO 6.0.7 are now available.
— Advanced Custom Fields (@wp_acf) January 18, 2023
✨This release contains bug fixes and improvements while we continue to work on the next major release of ACF.https://t.co/wQgAOpwmUI
© 2023 Advanced Custom Fields.
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.