Featured Image not loading with ajax

Posted in: Newspaper
Post count: 26

I have edited td_module_9 replacing the line:

echo $this->get_image('art-big-1col');

with:

if (has_post_thumbnail()) {
echo $this->get_image('art-big-1col');
} else {
get_the_image(array('order' => array('meta_key', 'scan', 'default'), 'meta_key' => 'featured_image', 'scan' => true, 'default' => 'default-img-326.jpg', 'image_class' => 'entry-thumb')); ?>
}

get_the_image function grabs an image from a custom field, if there is no image scans the post for images to get the first one and finally if post doesn’t contain images uses a default one.

This code works fine but when I insert module 9 inside a page with Visual Composer choosing ajax pagination, the featured images appear on the first page only but are not shown up when ajax tries to fetch them for next pages.

Is there anything I can do about that?

Thanks a lot.

Post count: 6600

Hi,

I believe this happens because the function doesn’t know the posts’s ID, try adding the post id argumnet, like this:

get_the_image(array('order' => array('meta_key', 'scan', 'default'), 'meta_key' => 'featured_image', 'scan' => true, 'default' => 'default-img-326.jpg', 'image_class' => 'entry-thumb', 'post_id' => $this->post->ID));

Thanks

Post count: 26

G.E.N.I.U.S.
Totally worked
Thanks so much!

Viewing 3 posts - 1 through 3 (of 3 total)
The forum ‘Newspaper’ is closed to new topics and replies.