Support » Fixing WordPress » 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?

    $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()){ ?>
    $args = array(
    'post_type' => 'attachment',
    'numberposts' => 25,
    'post_parent' => $post->ID,
    'order' => 'ASC'
    $attachments = get_posts($args);
    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)
  • 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;

    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.

    Why don’t you have a look at the method get_children();

    It might do what you are trying to do already.

    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.