Skip to content

Get image by term ID #27

Description

@rilwis

I want to get the image of a term (not the current queried term) to show outside the loop or taxonomy page template, like in menu, sidebar, etc. I found that there's no such filter for this purpose.

Right now, I have to use this solution, but I hope you can add the filter for getting image for a specific term in near future:

$term = get_term( $term_id, $taxonomy );
$tt_id = 0;
if ( isset( $term->term_taxonomy_id ) )
    $tt_id = (int) $term->term_taxonomy_id;

$associations = taxonomy_image_plugin_get_associations();
$image = '';
if ( isset( $associations[ $tt_id ] ) ) {
    $attachment_id = (int) $associations[ $tt_id ];
    $image = wp_get_attachment_image( $attachment_id, $size );
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions