Support » Fixing WordPress » Get attachments from posts/pages

  • Resolved Philip


    hi to the community,

    i’m building a gallery using wordpress and i try to get all images included in a page,
    so i have build an admin options page and from there i get the pages in a drop down and i have a problem filtering the content,

    i use this code to get the images,

    // Get the post ID
    $galleryID = $artdev_get_gallery1;

    // Get images for this post
    $arrImages =& get_children(‘post_type=attachment&post_mime_type= image&post_parent=’ . $galleryID );

    // If images exist for this page
    if($arrImages) {

    // Get array keys representing attached image numbers
    $arrKeys = array_keys($arrImages);

    // Get image attachments
    foreach ($arrKeys as $iNum) {

    // Get the thumbnail url for the attachment
    $sThumbUrl = wp_get_attachment_thumb_url($iNum);

    // Build the <img> string
    $sImgString = ‘<img src=”‘ . $sThumbUrl . ‘” width=”150″ height=”140″ alt=”image-alt” />’;

    // Print the image
    echo $sImgString;

    but i can’t filter the $artdev_get_gallery1 (is the drop down – page slug) to get the images from the selected page, it gets all the images from posts and pages also,
    if i change the drop-down (to the admin area) to a text area and write the page id as a number i can filter the content.

    i think that this is something simple but my knowledge is “newbie” and i can’t figure out how to do this.

    if anyone have a solution on this i will be very thankful,

    thanks a lot,

Viewing 1 replies (of 1 total)
  • i found a solution,
    just a call to db and return!!!

    SELECT ID FROM $wpdb->posts WHERE post_name


Viewing 1 replies (of 1 total)
  • The topic ‘Get attachments from posts/pages’ is closed to new replies.