wp_get_attachment_image returns different image size

It is a bug?

wp_get_attachment_image( $attachment_id, 'post-thumb-size-small');

Same code, called in template, and in AJAX call returns same image SRC, but different image width and height.

Read More

dumb from template call:

<img width="286" height="189" src="http://localhost/site/files/2012/02/post-image-31-286x189.jpg" class="attachment-post-thumb-size-small" alt="post-image-3" title="post-image-3">

dump from AJAX call

<img width="220" height="145" src="http://localhost/site/files/2012/02/post-image-31-286x189.jpg" class="attachment-post-thumb-size-small" alt="post-image-3" title="post-image-3">

i’m confused, whats wrong?

index.php code

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    <?php include 'post.php'; ?>

    <?php endwhile; endif; ?>

post.php code

<div class="container">

<?php
if( in_array( $post_type, array( 'audio', 'video', 'quote', 'link'))) {
  $theme->theme_post->display_post_element( $post_type, $post_size, $post);
}
?>
</div>

display_post_element function code

    function display_post_element( $post_type, $post_size, $post) {
$attachment_id = get_post_meta( $post->ID, '_view_attachment_id', true);
        if( $post_type == 'single_image') {
            $img = wp_get_attachment_image_src( $attachment_id, 'full');

            if( is_array( $img)):                
            ?>
            <div class="preview-thumb">
                <a href="<?php echo $img[0]; ?>" class="lightbox"><?php echo wp_get_attachment_image( $attachment_id, 'post-thumb-size-' . $post_size); ?></a>
                <a href="<?php echo $img[0]; ?>" class="lightbox zoom"></a>
            </div>
            <?php
            endif;
        }
}

load posts with ajax call code:

function load_posts_ajax() {
    global $post;
    $query_string = $_POST['query_string'];

    query_posts( $query_string . '&posts_per_page=' . get_option( 'posts_per_page') . '&post_status=publish&offset=' . (int)$_POST[ 'off']);

    if ( have_posts() ) : while ( have_posts() ) : the_post();
        include TEMPLATEPATH . '/post.php';
    endwhile; endif;

    die;
}

Related posts

Leave a Reply

1 comment