I have posts of custom taxonomy called Areas with terms such as Articles, Presentations, News etc. These terms are applied to the normal post-type "post".
Under a custom-post-type called "Company", I added an Advanced Custom Field Post Object with the field name associated_items
to select posts related to this Company.
Currently I have this function on my single-company.php
which shows the posts selected in ACF field associated_items
...
<?php $post_objects = get_field('associated_items');?>
<?php if( $post_objects ): ?>
<div class="relatedposts">
<h3>Related Posts</h3>
<?php foreach( $post_objects as $post): ?>
<?php setup_postdata($post); ?>
<?php get_template_part( 'content', 'excerpt' ); ?>
<?php endforeach; ?>
</div><!-- div.relatedposts -->
<?php wp_reset_postdata(); ?>
<?php endif; // end if( $post_objects ) ?>
The above code only outputs the posts selected in the ACF custom field associated_items
but in chronological order whereas I'd like it to be grouped according to taxonomy terms, for example like the following:
Posts related to the Company
Articles
- a post under the area "Articles"
- another post under the area "Articles"
- and another post under the area "Articles"
Presentations
- a post under the area "Presentations"
- another post under the area "Presentations"
- and another post under the area "Presentations"
News
- a post under the area "News"
- another post under the area "News"
- and another post under the area "News"
Many many many thanks in advance!