Get_post is not functioning properly.
-
I have multiple loops on my page and they’re all supposed to show images in a different div each time. Now I’m using get_post to fetch the ID from the post(upload in the cms) and this works perfectly on the first div, but when using the same method even when giving them different names get_post for some reason fetches “Hello world” the very first ID in wordpress and gives it to my images as a result I get empty src height and widths.
Why does this happen? I reset postdata after every query.
This is my code:
<?php if( have_rows('gallery_project') ): while( have_rows('gallery_project') ): the_row(); // vars $image = get_sub_field('afbeelding'); $content = get_sub_field('caption'); $post_ID = get_post($image); $afbeelding = image_downsize( $post_ID->ID, 'een3e'); $alt_img = $post_ID->post_title; /* $afbeelding[0] = src $afbeelding[1] = width $afbeelding[2] = height $afbeelding[3] = resized bool */?> <div class="col_4"> <div class="thumbnail-cont"> <img src="<?php echo $afbeelding[0]; ?>" width="<?php echo $afbeelding[1]; ?>" alt="<?php echo $alt_img; ?> "/> <?php //echo $content; ?> </div> </div> <?php endwhile; wp_reset_postdata(); endif; ?>
I use the same code 3x but change the names for instance: $image2 or $image 3.
Thanks in advance!
[Moderator Note: No bumping. If it’s that urgent after just 13 minutes(!), consider hiring someone instead.]
- The topic ‘Get_post is not functioning properly.’ is closed to new replies.