Sometimes things that should be easy are hard…
Today, I needed to display an Advanced Custom Fields (ACF) image on a custom taxonomy page. Here’s the solution:
First, create the image field and apply it to the taxonomy like this:
Make sure you have the image field set to output the “Image Array” like this:
Now, go to your taxonomy term and add an image like this:
Finally, copy-and-paste code to your functions.php:
add_action( 'loop_end', 'output_before_taxonomy_loop' );
function output_before_taxonomy_loop(){
if (is_tax()) {
// Display the artist image
$queried_object = get_queried_object();
$taxonomy = $queried_object--->taxonomy;
$term_id = $queried_object->term_id;
$terms = get_field( 'artist_image', $taxonomy.'_'.$term_id);
if( $terms ) {
echo '<img src="'. $terms['url'] .'">';
} else {
//do nothing
}
}
}
Finally, bask in the glory that is Advanced Custom Fields’ taxonomy image fields!
Ain’t life grand? Well…mostly?
More posts from themightymo.com
The Mighty Moo! WordPress Theme Version 1.2.4 Update
I added the following functionality to The Mighty Moo! WordPress theme: Custom stylesheet class example Basically, what I did was add an example to the custom stylesheet to get you rolling. 🙂
The Mighty Moo! WordPress Theme – Version 1.2.3
I just completed another series of updates to “The Mighty Moo!” WordPress theme. Version 1.2.3 adds: Page Template Widgetized Sidebars underneath the content Moved javaScript code into footer.php Theme image files (these were accidentally left out of previous releases) Download it today!
The Mighty Moo! WordPress Theme, Version 1.2.2 Released
Today, I spent eight hours making a number of significant updates to The Mighty Moo! WordPress theme. This set of updates increases the version number to 1.2.2. and include: Single Page template Comment Threading Fixed Commenting bug Custom Style Sheet (Upgrades now won’t mess up your custom CSS edits!) The next round of updates will…