Home › Forums › General Issues › Using Taxonomy to display custom posts › Reply To: Using Taxonomy to display custom posts
Hey!
So you’re sort of twisting and turning the query around. You start off with terms which you use to query posts which then are used to show terms.
Your code is a bit confusing.. I’ll post a cleaned up version here but first I want to talk about what it does.
So with the current code you fetch ALL terms in the taxonomy systemcontents_category2
. You then loop through each term and perform a wp_query which fetches all posts connected to that term.
Then you loop through each post and output the terms name and some information from the post.
Nowhere is $selected
being used and I don’t quite get what it is you want to use it for either. You should also be using ACFs API functions like get_field()
to fetch the meta values for the post.
If this is not what you need please try to explain further and possibly include a screenshot of your ACF setup.
<?php
$member_group_terms = get_terms('systemcontents_category2');
$selected = get_sub_field('system_contents_posts');
?>
<?php foreach ( $member_group_terms as $member_group_term ) endforeach; ?>
<?php
$args = array(
'post_type' => 'pj_systemcontents2',
'posts_per_page' => 400, //unlikely high
'tax_query' => array(
array(
'taxonomy' => 'systemcontents_category2',
'field' => 'slug',
'terms' => array( $member_group_term->slug ),
'operator' => 'IN'
)
)
);
$member_group_query = new WP_Query($args);
?>
<?php if ( $member_group_query->have_posts() ) : ?>
<h3><?php echo $member_group_term->name; ?></h3>
<?php while ( $member_group_query->have_posts() ) : $member_group_query->the_post(); ?>
<?php echo get_field('document-section'); ?>
<?php echo get_field('document-reference') . ' ' . get_field('document-sub-section'); ?>
<?php endwhile; wp_reset_postdata(); ?>
<?php endif; ?>
<?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!
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.