Title: post_parent problem
Last modified: August 19, 2016

---

# post_parent problem

 *  [md84](https://wordpress.org/support/users/md84/)
 * (@md84)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/post_parent-problem/)
 * Hi,
 * ‘post_parent’ => $post->ID returns a blank page, when using null it works, but
   that’s not what I want. I want to collect the attachments of its parent (or a
   specified post).
 * Does anybody know what’s the problem?
 *     ```
       <?php
       $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
       $wp_query = new WP_Query();
       $wp_query -> query('category_name=photo&posts_per_page=1&order=ASC&paged=' . $paged);
       ?>
   
       <?php while($wp_query -> have_posts()) : $wp_query -> the_post(); ?>
   
       <?php if(is_paged()){ ?>
   
       <?php
       $args = array(
       'post_type' => 'attachment',
       'numberposts' => 25,
       'post_parent' => $post->ID,
       'order' => 'ASC'
       );
   
       $attachments = get_posts($args);
       if($attachments){
       foreach($attachments as $attachment){
       $atturl = wp_get_attachment_thumb_url($attachment->ID);
       $attlink = get_attachment_link($attachment->ID) . '&paged=' . $paged;
       echo '<a href="' . $attlink . '"><img src="' . $atturl . '"></a>';
       }
       };
       ?>
   
       <?php } else { ?>
       <?php the_content(); ?>
       <?php }; ?>
   
       <?php endwhile; ?>
       ```
   

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

 *  [jimisaacs](https://wordpress.org/support/users/jimisaacs/)
 * (@jimisaacs)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/post_parent-problem/#post-1452095)
 * Can you rephrase?
 * > ‘post_parent’ => $post->ID returns a blank page, when using null it works
 * Depending on your template, I see you are using quite a bit of globals, and you
   may need to appease that in your code.
 * Try at the top:
 * `global $wp_query, $post;`
 *  Thread Starter [md84](https://wordpress.org/support/users/md84/)
 * (@md84)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/post_parent-problem/#post-1452121)
 * Hey, thanks for the reply. Let me rephrase it.
 * In my code, when I use ‘null’ as value for argument ‘post_parent’, it shows all
   attachments (as thumbnails), so that works. But what I actually want is only 
   showing attachments from certain posts. The value ‘$post->ID’ should provide 
   me with the attachments of its parent, but it doesn’t work (no attachments show).
 * I also tried using global $wp_query, $post; but it didn’t solve it.
 *  [jimisaacs](https://wordpress.org/support/users/jimisaacs/)
 * (@jimisaacs)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/post_parent-problem/#post-1452140)
 * Why don’t you have a look at the method [get_children();](http://codex.wordpress.org/Function_Reference/get_children)
 * It might do what you are trying to do already.
 *  Thread Starter [md84](https://wordpress.org/support/users/md84/)
 * (@md84)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/post_parent-problem/#post-1452181)
 * Tried it, didn’t work! The problem remained.
 * It’s still the same as explained above. All attachments are shown when using ‘
   null’ as value for argument ‘post_parent’, but when using ‘$post->ID’ or argument‘
   include’ with as value a number of a specified post, it doesn’t work and shows
   nothing.

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

The topic ‘post_parent problem’ is closed to new replies.

## Tags

 * [get_posts](https://wordpress.org/support/topic-tag/get_posts/)
 * [id](https://wordpress.org/support/topic-tag/id/)
 * [paged](https://wordpress.org/support/topic-tag/paged/)
 * [post](https://wordpress.org/support/topic-tag/post/)
 * [post_parent](https://wordpress.org/support/topic-tag/post_parent/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [md84](https://wordpress.org/support/users/md84/)
 * Last activity: [16 years, 1 month ago](https://wordpress.org/support/topic/post_parent-problem/#post-1452181)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
