Created
          October 19, 2022 20:57 
        
      - 
      
 - 
        
Save mwhiteley16/4783e485856498c3a5d3dc14b309b9d6 to your computer and use it in GitHub Desktop.  
    Get Category Image ID Helper
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <?php | |
| /** | |
| * Helper function to get ID of feast category image | |
| * | |
| * @since 7.7.0 | |
| * | |
| * @param string $taxonomy Name of the taxonomy | |
| */ | |
| function get_feast_category_image_id( $term ) { | |
| // check if category exists | |
| if ( ! category_exists( $term ) ) { | |
| return; | |
| } | |
| // get associated term ID | |
| $term_object = get_term_by( 'slug', $term, 'category'); | |
| $term_id = $term_object->term_id; | |
| // get feast category imgae URL | |
| $feast_category_image_url = get_term_meta( $term_id, 'feast-category-image-url', true ); | |
| // check if term has associated feast category image URL | |
| if ( empty( $feast_category_image_url ) ) { | |
| return; | |
| } | |
| $feast_category_image_id = attachment_url_to_postid( $feast_category_image_url ); | |
| return $feast_category_image_id; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment