Skip to content

Commit

Permalink
Better logic for the $meta_key. Make sure $image_html is set so it do…
Browse files Browse the repository at this point in the history
…esn't throw an error.

git-svn-id: http://svn.locallylost.com/themes/hybrid-core/trunk@982 dba0f204-706d-4bc1-bc29-8b92e0485636
  • Loading branch information
greenshady committed Feb 15, 2012
1 parent 78e363b commit 6299322
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions extensions/get-the-image.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ function get_the_image( $args = array() ) {
if ( !is_array( $image_cache ) )
$image_cache = array();

/* Set up a default, empty $image_html variable. */
$image_html = '';

/* If there is no cached image, let's see if one exists. */
if ( !isset( $image_cache[$key] ) || empty( $cache ) ) {

Expand Down Expand Up @@ -205,25 +208,18 @@ function get_the_image( $args = array() ) {
function get_the_image_by_meta_key( $args = array() ) {

/* If $meta_key is not an array. */
if ( !is_array( $args['meta_key'] ) ) {

/* Get the image URL by the single meta key. */
$image = get_post_meta( $args['post_id'], $args['meta_key'], true );
}
if ( !is_array( $args['meta_key'] ) )
$args['meta_key'] = array( $args['meta_key'] );

/* If $meta_key is an array. */
elseif ( is_array( $args['meta_key'] ) ) {
/* Loop through each of the given meta keys. */
foreach ( $args['meta_key'] as $meta_key ) {

/* Loop through each of the given meta keys. */
foreach ( $args['meta_key'] as $meta_key ) {
/* Get the image URL by the current meta key in the loop. */
$image = get_post_meta( $args['post_id'], $meta_key, true );

/* Get the image URL by the current meta key in the loop. */
$image = get_post_meta( $args['post_id'], $meta_key, true );

/* If an image was found, break out of the loop. */
if ( !empty( $image ) )
break;
}
/* If an image was found, break out of the loop. */
if ( !empty( $image ) )
break;
}

/* If a custom key value has been given for one of the keys, return the image URL. */
Expand Down

0 comments on commit 6299322

Please sign in to comment.