You will need to use get_the_terms()
to get the taxonomy terms associated with the post and loop through them until you find one that has an image set:
$post. = get_queried_object();
$terms. = get_the_terms( $post, 'taxonomy_name_here' );
$image_url = null;
if ( $terms && ! is_wp_error( $terms ) ) {
foreach ( $terms as $term ) {
$attachment_id = get_term_meta( $term->term_id, 'category-image', true );
if ( $attachment_id ) {
$image_url = wp_get_attachment_image_url( $attachment_id, 'full' );
break;
}
}
}
if ( $image_url ) {
// Output image as needed.
}
Related Posts:
- How to pass URL parameters for advanced taxonomy queries with multiple terms for one custom taxonomy
- How to display posttypes and taxonomy in standard posts, not in a separate label?
- ACF – Retrieve custom taxonomy from a relationship field
- Display Custom Field or Custom Taxonomy in front page /post/product
- Custom taxonomy template for custom fields loop [closed]
- Storing/querying custom date data
- Custom Post Type Taxonomy Filters
- Query with no terms uses index.php template instead of archive.php
- search also in taxonomy, tags and custom fields
- Create template for taxonomy results limited by Custom Post Type
- Template for custom post with custom taxonomy
- How do I associate a custom post type with another through a taxonomy or storing an ID in a custom field?
- Custom post type content using custom fields without template
- Show custom post type relationships by taxonomy
- Custom taxonomy and custom post type – wrong permalinks and template
- WordPress loop: Show only a Custom Post Type Taxononmy TERM
- Dynamic dropdown select values depending on other custom field value
- How to conditionally redirect to the post from a taxonomy page?
- WordPress Doesn’t Generate Taxonomy Archive
- Hierarchy and access control for Custom Post Types (CPT)
- Custom taxonomy returns 404
- First custom field value (out of several) displayed twice after query
- Adding Page Templates to post but it ignored it
- Template for all categories of a custom post type?
- How to group posts and get a mixed posts and groups view?
- Migrating a taxonomy’s tags to the native category
- How to display products name in a non-alphabetical order, in a custom field (taxonomy)?
- WordPress custom taxonomy template not working
- Show fields based on taxonomy selection in editor
- Permalinks: custom structure for taxonomy – tags?
- How can I get this request to use the Custom Post Type page template instead?
- Archive for a Taxonomy of a Custom Post type
- Template files for Custom Post Type and Taxonomy
- Custom post type’s extra fields – how to handle?
- Main query not querying any posts in custom taxonomy template
- Loop through custom posts by taxonomy and display the titles in a list, it is repeating 8 times
- Creating custom post type with custom taxonomy and custom fields programatically
- How to list tags from custom post type attachments?
- Targeting categories in custom fields
- Custom taxonomies to define versions of a product
- Which file/template is in charge of taxonomies for custom post types?
- Custom Taxonomy Search result page
- Category Search / Custom Post Type search on my website. Custom Post Types that are “page-like”?
- Many to many to many custom post relationships
- Display a post from custom post type only if all the selected taxonomies and custom field value matches the record
- How to fetch custom post types with its full data on wordpress?
- Reusable metabox backend and frontend
- How to populate a Gravity Forms Custom Post Field (dropdown type) with custom taxonomy terms? [closed]
- Get custom term meta problem on single post type
- Custom post type name and assigning custom taxonomy
- Get template part with CPT and Custom Taxonomy conditionals
- I have custom post type with custom taxonomy. But not found the taxonomy page..
- How to create a template to show child terms of a MAIN taxonomy
- How to change single custom post template by custom taxonomy?
- Get A Custom Field From A Custom Taxonomy Of A Custom Post Type [closed]
- Building a Portfolio and need some direction
- Custom post types category
- How to List Custom Post Type Titles Based on Theirs Taxonomy Terms Inside a Nested Loop
- Custom Taxonomy dont save in a frontend form for post a custom post
- Custom Post type Query by Taxonomy
- Single.php for Custom Post Type > Taxonomy > Term
- Create a custom taxonomy template that loops through child categories in term order?
- Display Posts Query with IF function
- Making a form for user to add new custom post with custom taxonomies and custom fields
- Should i use custom post type for a custom footer?
- Order custom posts by taxonomy, then by meta_key
- Confusion about how to use Custom Post Types, Custom Taxonomy or Category?
- Displaying Posts Using a Custom Query with a Custom Field and a term_id
- Writing a custom Glossary plugin
- How do I ensure that post_type and Taxonomy use the same slug?
- add_filter get array data before display in custom post_type
- Custom taxonomy terms as children of multiple custom post types
- Custom Post Type meta data getting deleted on bulk editing taxonomies
- Post template with breadcrumb needs to show page navigated from
- Display Posts that fit a certain criteria on Category pages
- Add custom template ‘sub-page’ to Custom Post type?
- WP_Query not using custom taxonomy categories on custom post type
- wp_insert_post deleting previous post custom meta
- Custom Post Taxonomy Template Not Loading Properly
- PHP Warning with Custom Fields
- I want to create a metabox under custom taxonomy
- Adding a Section for Visitors
- Query posts by multiple custom fields
- taxonomy – templates are not loading
- Custom taxonomy with custom post type template not showing
- Showing taxonomies with terms that are attached to custom post
- Getting all custom post taxonomies and exhibiting only part of them
- Templates for CPT not working
- Single taxonomy for different custom post types
- Error get_posts with Custom Taxonomy and OR relation
- Create Inclusions and exclusions
- How should i name the .php file to show custom posts under a taxonomy’s term?
- What’s the most efficient way to get two queries based on an if statement?
- I want to create an archive and single page for a custom taxonomy for a custom post type
- Custom Post Type tag taxonomy “Page Not Found”
- Need some suggestion/help with custom post types project
- Best way to use Category & Custom Fields?
- template structure for CPT not clear
- WordPress Custom taxonomy template
- Get list of CPT posts in *current* post’s taxonomy term