wordpress - get_posts() always empty for post_type attachment -


i struggling following while working on wordpress theme:

as title suggests, array returned get_posts() empty despite posts holding images.

i using following retrieve attachments-array:

$attachments = get_posts( array(     'post_type' => 'attachment',     'posts_per_page' => -1,     'post_parent' => $post_id ) ); 

now, $post_id works fine...if echo right before above snippet shows without fail. can't make out error is.

for sake of completeness, heres whole loop, works fine in every regard except attachment retrieval:

           <?php if (have_posts()) : ?>             <?php while (have_posts()) : ?>                 <?php the_post(); ?>                 <div class="post" id="post-<?php the_id(); ?>">                     <div class="post-border">                         <div class="post-date"><?php edit_post_link('edit post', '', ''); ?></div>                         <?php if($pagename == 'news'): ?>                             <div class="post-date">posted: <?php the_time('f j, y') ?></div>                         <?php endif; ?>                         <h5 class="posttitle"><?php the_title(); ?></h5>                         <div class="post-entry">                             <?php the_content(); ?>                             <?php                                 $post_id = $post -> id;                                 echo $post_id;                                 $attachments = get_posts( array(                                     'post_type' => 'attachment',                                     'posts_per_page' => 20,                                     'post_parent' => $post_id                                 ) );                                 print_r($attachments);                             ?>                         <?php echo "<div class='clearboth'></div>"; ?>                         </div> <!-- end of .entry -->                     </div> <!-- end of .post-border -->                 </div> <!-- end of .post -->             <?php endwhile; ?>         <?php endif; ?> 

if has suggestions i'd grateful!

best, j

attachments inherit post_status parent post, add following args:

'post_status' => 'inherit', 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -