Home › Forums › General Issues › Taxonomy Relationship › Reply To: Taxonomy Relationship
Thanks for the follow up. I’ll add in the taxonomy field docs soon, but for the time being, you can see the data available with some simple debugging:
<?php
$taxonomies = get_field('field_name');
echo '<pre>';
print_r( $taxonomies );
echo '</pre>';
die;
?>
The above example shows how you can load the taxonomy field values (when viewing a speaker post), and then simple output them visually so you can see the available data.
To then get all ‘related’ speakers from that year, you can query the posts like so:
<?php
$taxonomies = get_field('field_name');
// args
$args = array(
'numberposts' => -1,
'post_type' => 'speaker',
'tax_query' => array(
array(
'taxonomy' => 'year',
'field' => 'slug',
'terms' => array()
),
)
);
if( $taxonomies )
{
foreach( $taxonomies as $term )
{
$args['tax_query']['terms'][] = $term->slug;
}
}
// get results
$the_query = new WP_Query( $args );
?>
Please note that the above is not tested, and I am assuming that the variable $term has a property called slug.
Please debug the code to make sure the data is correct.
Hope that helps.
thanks
E
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.