WordPress.org

Ready to get started?Download WordPress

Forums

"get_children" not working on archive (5 posts)

  1. omnialex
    Member
    Posted 2 years ago #

    I'm using this code within the loop to display the number of photos attached in each post and it works perfectly on the single.php template but on the archive template it only displays 0:

    <?php $attachments = get_children(array('post_parent'=>$post->ID)); $nbImg = count($attachments); echo $nbImg; ?>

    Any suggestions? I'm guessing it's to do with the $post->ID but I'm not sure how to work around that...

  2. keesiemeijer
    moderator
    Posted 2 years ago #

    Is this inside the loop?

  3. omnialex
    Member
    Posted 2 years ago #

    Yes, my loop starts like this and is pretty straightforward:

    <?php while (have_posts()) : the_post(); ?>

  4. keesiemeijer
    moderator
    Posted 2 years ago #

    try it with this:

    <?php $attachments = get_children('post_parent='.$post->ID);
    $nbImg = count($attachments); echo $nbImg; ?>
  5. omnialex
    Member
    Posted 2 years ago #

    Same result :(

Topic Closed

This topic has been closed to new replies.

About this Topic