• Resolved jagallagher

    (@jagallagher)


    I’m trying to display a set of images which are defined in a custom field, seperated by line breaks. As I’m calling the images via ajax, and I need to reinitialize my jscrollpane bar, I need to include the widths in the img tags.

    My image loop looks like this:

    <?php
    $images = get_post_meta($post->ID, 'designs');
    if($images) { ?>
    <div class="display">
    <?php
    $images = nl2br($images[0]);
    $images = explode('<br />',$images); ?>
    <?php foreach($images as $image){
    $imgid = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE guid = '" . $image . "'" );
    $imgmeta = wp_get_attachment_metadata( $imgid );
    	echo "<img src=". $image ." width=". $imgmeta['width'] ." height=". $imgmeta['height'] ." />";
    	} ?>
    </div>
    <?php } ?>

    What I’m finding is that html the first image is appearing correctly, with the width and height, but the html I’m getting for the second and subsequent images is displaying as follows:

    <img src="path/to/image.jpg" width="height=" />

    I’m sure it’s probably something simple, but I’ve been staring at it for ages and can’t figure out what’s wrong. Can anyone see what I’m doing wrong here?

    Thanks in advance

Viewing 1 replies (of 1 total)
  • Thread Starter jagallagher

    (@jagallagher)

    In case anyone else has a similar problem, I found that there was a single space at the start of each occurence of $image after the first one. I solved the issue by changing

    $imgid = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE guid = '" . $image . "'" );

    to

    $imgid = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE guid = '" . trim($image) . "'" );

Viewing 1 replies (of 1 total)
  • The topic ‘Problem with wp_get_attachment_metadata’ is closed to new replies.