Home › Forums › General Issues › Get taxonomy name from 'Taxonomy' field and insert into custom loop as category? › Reply To: Get taxonomy name from 'Taxonomy' field and insert into custom loop as category?
Do your have the field set to save and load terms?
the taxonomy query added to your arguments should look something like this: see https://codex.wordpress.org/Class_Reference/WP_Query
$args = array (
'post_type' => 'exercise-database',
'tax_query' => array(
array(
'taxonomy' => 'your taxonomy here',
'terms' => array($term_id), // <= this needs to be an array of term id, can have a single value
'operator' => 'IN'
)
),
'pagination' => true,
'paged' => $paged,
'order' => 'DESC',
);
But before you go to the trouble of creating a custom page template for every category you should think about using the template hierarchy built into WP. If you have a custom post type and you add a custom taxonomy for the CPT then you only need to create 3 template files: archive-{$custom-post-type}.php
, single-{$custom-post-type}.php
and taxonomy-{$custom-taxonomy}.php
. It would be a lot easier than building and doing custom queries for every category.
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.