However, what if you want to access it outside of the
In this example, your ACF field is named ‘associated_image’ and ‘chosen-image-size’ is the desired image size that is set within your theme. Note: the ACF field is also set to return an array.
Full Snippet Example:
// Retrieves post categories' object outside the loop. $cat = get_the_category(); // Narrows down to get term ID. $term_id = $cat->term_id; // Get all term data via term ID. $term = get_term( $term_id ); $attachment_id = get_field( 'associated_image', $term ); // URL of image at specific size. $media = $attachment_id['sizes'][ $size ]; return $media;