Howdy!
I reached out on the forums initially but the only reply I've gotten so far which also linked a page that is supposed to do what I need didn't work. What I am trying to do should be easy but unless I do a complicated multi-table lookup I can't get what I need.
https://support.advancedcustomfields.com/forums/topic/get-custom-field-on-custom-taxonomy/
Basically I have archive.php which I want to use for every archive. I have a custom taxonomy called review-series. I have two ACF fields including review_series_featured_image which if present I want to use as a background-image.
I need to do this outside of the loop as posts could have more than one review-series, I only care about the review-series in play on archive.php. In this example archive.php is called with this URL: /review-series/reviewed-from-vhs/
I can use is_tax() to determine is this is true as well as get the appropriate term_id with get_queried_object_id():
$fanart = get_template_directory_uri() . '/img/films-fanart.jpg';
$archive_id = get_queried_object_id();
if ( is_tax( 'review-series' ) ) {
// if ( get_field( 'review_series_featured_image', $archive_id ) ) {
// $fanart = get_field( 'review_series_featured_image', $archive_id );
// }
echo '<div>get_queried_object_id() = ' . $archive_id . ', $fanart=' . $fanart . '</div>';
// outputs <div>get_queried_object_id() = 22364, $fanart=http://outlawvern.local/wp-content/themes/vern2019/img/films-fanart.jpg</div>
}
If I uncomment the inner "if" clause the page crashes. If I change get_field() to 'term_' . $archive_id it still crashes. None of the code on the linked page the helpful user provided works either:
https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/
I can write the SQL myself:
SELECT wp_postmeta.meta_value
FROM wp_postmeta
INNER JOIN wp_termmeta ON wp_postmeta.post_id = wp_termmeta.meta_value
WHERE wp_termmeta.term_id = 22364 AND
wp_termmeta.meta_key = 'review_series_featured_image' AND
wp_postmeta.meta_key = '_wp_attached_file';
But I figure there must be a way with standard WordPress and ACF functions.
Thanks,
Chris