pods_image_id_from_field

Get the Attachment ID for a specific image field.

Description

(int) pods_image_id_from_field( (array|int|string) $image ); 

Returns (int)

Attachment ID

Parameters (1)

0. $image (array|int|string)
The image field array, ID, or guid

Usage

  1. if ( !function_exists( 'pods_image_id_from_field' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'pods-custom-content-types-and-fields/includes/media.php'; 
  3.  
  4. // The image field array, ID, or guid 
  5. $image = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = pods_image_id_from_field($image); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/media.php  
  1. function pods_image_id_from_field ( $image ) { 
  2. $id = 0; 
  3.  
  4. if ( !empty( $image ) ) { 
  5. if ( is_array( $image ) ) { 
  6. if ( isset( $image[ 0 ] ) ) 
  7. $id = pods_image_id_from_field( $image[ 0 ] ); 
  8. elseif ( isset( $image[ 'ID' ] ) ) 
  9. $id = $image[ 'ID' ]; 
  10. elseif ( isset( $image[ 'guid' ] ) ) 
  11. $id = pods_image_id_from_field( $image[ 'guid' ] ); 
  12. elseif ( isset( $image[ 'id' ] ) ) 
  13. $id = $image[ 'id' ]; 
  14. else 
  15. $id = pods_image_id_from_field( current( $image ) ); 
  16. else { 
  17. if ( false === strpos( $image, '.' ) && is_numeric( $image ) ) { 
  18. $id = $image; 
  19.  
  20. $the_post_type = get_post_type( $id ); 
  21.  
  22. if ( false === $the_post_type ) 
  23. $id = 0; 
  24. elseif ( 'attachment' != $the_post_type ) 
  25. $id = get_post_thumbnail_id( $id ); 
  26. else { 
  27. $guid = pods_query( "SELECT `ID` FROM @wp_posts WHERE `post_type` = 'attachment' AND `guid` = %s", array( $image ) ); 
  28.  
  29. if ( !empty( $guid ) ) 
  30. $id = $guid[ 0 ]->ID; 
  31.  
  32. $id = (int) $id; 
  33.  
  34. return $id;