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
Google Removed Our Business Listing – How we restored our biz to the Map and got our reviews back.
I was about to send an email to a potential customer pointing them to our 5-star Google Reviews via our Google Business profile (e.g. the Google Map), hoping this added information about our customers’ past experiences might help me close a deal. But when I checked the Google Reviews link, it was down. And after…
The Price We Pay: Cloudways Off-Site Backup vs. Budget WordPress Hosts
Cloudways Off-Site Backup Pricing Calculator: The Ultimate Cost Guide
How to Block Mailinator and other spam from Gravity Forms
I’ve had a couple of scenarios where I’ve needed to block a specific domain from filling out Gravity Forms on my WordPress site. Today I needed to block spammy “mailinator.com” submissions from a contact form. The solution was simple: Install and configure the Gravity Forms Email Blacklist plugin. In a few minutes – all done!