Title: Get_post is not functioning properly.
Last modified: August 21, 2016

---

# Get_post is not functioning properly.

 *  Resolved [Dvd709](https://wordpress.org/support/users/dvd709/)
 * (@dvd709)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/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](http://codex.wordpress.org/Forum_Welcome#No_Bumping).
   If it’s that urgent after just 13 minutes(!), consider [hiring someone](http://jobs.wordpress.net/)
   instead.]_

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Dave Naylor](https://wordpress.org/support/users/wpranger/)
 * (@wpranger)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/get_post-is-not-functioning-properly/#post-4531531)
 * What typical value would be assigned to the variable `$image` here:
 * `$image = get_sub_field('afbeelding');`
 * It’s worth pointing out that `get_sub_field()` is not a WordPress native function,
   it’s part of [Advanced Custom Fields](http://www.advancedcustomfields.com/) and
   as far as I am aware, only available as a Premium Add-on.
 *  Thread Starter [Dvd709](https://wordpress.org/support/users/dvd709/)
 * (@dvd709)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/get_post-is-not-functioning-properly/#post-4531536)
 * EDIT: I solved it the reason it didn’t work is because I forgot to change the
   custom subfield at the Return Value option to ID. Stupid of me!
 * Regardless of that, thanks WPRanger!
 *  [Bazan](https://wordpress.org/support/users/bazan/)
 * (@bazan)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/get_post-is-not-functioning-properly/#post-4531539)
 * For the future i can give You an advice.
 * Instead of using subfields etc.
 * U can save all the repeater field values in 1 array by:
 * `$repeater = get_field('repeater_name');`
 * Then u can `var_dump($repeater);`
 * and use:
 *     ```
       foreach ($repeater as $item) :
          echo $item['my_title'].' - '.$item['my_other_field'].'<br>';
       endforeach;
       ```
   
 * Its easier to navigate than use get_sub_field and have_rows()

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Get_post is not functioning properly.’ is closed to new replies.

## Tags

 * [get_post](https://wordpress.org/support/topic-tag/get_post/)
 * [image](https://wordpress.org/support/topic-tag/image/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 3 participants
 * Last reply from: [Bazan](https://wordpress.org/support/users/bazan/)
 * Last activity: [12 years, 4 months ago](https://wordpress.org/support/topic/get_post-is-not-functioning-properly/#post-4531539)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
