• Resolved nateomedia

    (@nateomedia)


    $attachments = get_children(array( 'post_type' => 'attachment', 'post_status' => 'inherit', 'numberposts' => 999, 'post_parent' => $post->ID ));

    This bit of code normal returns all of the attachments on a post. After upgrading to 3.1, it stopped working. Using print_r on $attachments shows it to be an empty array.

    This is being used inside the WordPress loop.

    I took a peek with phpmyadmin to see if it was a database problem, but the image I’m testing on meets the criteria of my get_children request.

    I downgraded back to 3.05 and the problem persists, so I think it’s a database issue. I consider myself to have a pretty strong understanding of WordPress, but I’m weak on the database side. Any suggestions of how to work around this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter nateomedia

    (@nateomedia)

    Okay, figured out how to work around this:

    $attachments = $wpdb->get_results("SELECT $wpdb->posts.* FROM $wpdb->posts WHERE $wpdb->posts.post_type='attachment' AND $wpdb->posts.post_parent='" . $post->ID . "' ORDER BY post_date DESC");

    This appears to be a bug, but I’m not comfortable filing it because I don’t know why this is happening.

    darrenbond

    (@darrenbond)

    I too am having problems with a bit of code that I use to return the first image attachment of a post. Worked fine before I upgraded to 3.1.

    <?php $attachments = get_children( array(
    				'post_parent'    => get_the_ID(),
    				'post_type'      => 'attachment',
    				'numberposts'    => 1, // show all -1
    				'post_status'    => 'inherit',
    				'post_mime_type' => 'image',
    				'order'          => 'ASC',
    				'orderby'        => 'menu_order ASC'
    				) );
    foreach ( $attachments as $attachment_id => $attachment ) {
    	echo wp_get_attachment_image( $attachment_id, 'medium' );
    } ?>

    Are you able to help me with a work-around?

    Many thanks.

    darrenbond

    (@darrenbond)

    I resolved this by changing the following :

    'post_parent' => get_the_ID(),

    changed to

    'post_parent' => $pageChild->ID,

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘3.1 get_children attachment problem’ is closed to new replies.