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
- Taxonomy: Why ‘with_front’ => false DOES NOT WORK?
- Taxonomy, Terms, and Template Files
- clients list using wordpress
- Templates for Custom Post Types and Custom Taxonomies
- Get page by template?
- Creating Photo Gallery System with Custom Post Type
- Custom taxonomy query for a custom post type
- How to do a custom bookmarks post type?
- Custom SQL Query on Custom Post Type. Order by Taxonomy?
- WordPress Search documentation: how to improve search query using taxonomy terms, custom meta fields?
- Custom Post Type Archive Template
- How to select one major category (or custom taxonomy) for a custom post type?
- Automatically assign a custom post to a custom taxonomy based on custom field value
- Custom Taxonomy order by Custom Field
- front end radio custom taxonomy with custom post type
- Is there any performance consideration when using Custom Post Types?
- Trying to manage templates on a blog with lots of custom taxonomies
- What is better: Custom Fields vs Custom Taxonomies with Terms for perfomance, scalability and better user experience
- Custom taxonomy template not working with simple loop. Multiple CPT using the same taxonomy
- How loop through posts based on custom fields
- How to add custom fields to admin UI and REST API response?
- Get Custom Field Values by Another Custom Field in WordPress
- Custom Post Type Taxonomies -Posts not showing in Category or Tag pages
- How to bulk copy custom fields between custom posts?
- Retrieve value of a category’s custom field
- wp_query check if integer exists in custom field’s array
- Custom post type templating problem
- search also in taxonomy, tags and custom fields
- Template for custom post with custom taxonomy
- Custom post type content using custom fields without template
- 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
- WordPress Doesn’t Generate Taxonomy Archive
- Custom taxonomy returns 404
- 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?
- WordPress custom taxonomy template not working
- 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
- 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?
- Display a post from custom post type only if all the selected taxonomies and custom field value matches the record
- Reusable metabox backend and frontend
- How to populate a Gravity Forms Custom Post Field (dropdown type) with custom taxonomy terms? [closed]
- Custom post type name and assigning custom taxonomy
- Get template part with CPT and Custom Taxonomy conditionals
- 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
- Single.php for Custom Post Type > Taxonomy > Term
- 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?
- How do I ensure that post_type and Taxonomy use the same slug?
- 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
- Add custom template ‘sub-page’ to Custom Post type?
- PHP Warning with Custom Fields
- Adding a Section for Visitors
- 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
- 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?
- Custom Post Type tag taxonomy “Page Not Found”
- Need some suggestion/help with custom post types project
- template structure for CPT not clear
- WordPress Custom taxonomy template
- Get list of CPT posts in *current* post’s taxonomy term
- tax_query showing no results
- predefined custom field on registration page
- How to display custom post types AND regular posts separately on a shared taxonomy archive?
- Querying multiple taxonomies in URL leads to wrong taxonomy archive
- Advanced search form with filters for custom taxonomies and custom fields
- Listing all custom post types using a specific term on the said term’s template page, in groups
- Custom Post type as Taxonomy
- Only One Post of Custom Post Type Appearing on Template Page
- How to change order of custom post types. I want Featured post to come first
- I want to understand plugin implementation of custom posts / taxonomies / metaboxes
- Custom Sort Order for Custom Post Type Taxonomy