WordPress.org

Ready to get started?Download WordPress

Forums

Calling $attachments from multiple pages (3 posts)

  1. pet3r
    Member
    Posted 1 year ago #

    I have a script on my site that displays images that are attached to the page. Currently it is only displaying photo attachments on that page only.

    Is there any way to call attachments from other pages via page IDs?

  2. David Choi
    Member
    Posted 1 year ago #

    You probably have to create a function in your functions.php file using

    http://codex.wordpress.org/Function_Reference/has_post_thumbnail

    it accepts the page ID. You can make your function as shortcode

    http://codex.wordpress.org/Shortcode_API

    so it can be inserted into your posts.

    I haven't seen a plugin for this yet (although it might exist).

  3. pet3r
    Member
    Posted 1 year ago #

    I currently have this array on a page:

    <?php $args = array(
    'orderby' => 'menu_order',
    'order' => 'ASC',
    'post_type' => 'attachment',
    'post_parent' => $page_id = 1339,
    'post_mime_type' => 'image',
    'post_status' => null,
    'numberposts' => $imageNumber
    );
    $attachments = get_posts($args);

    $args2 = array(
    'post_type' => 'attachment',
    'post_parent' => $page_id = 1339,
    'post_mime_type' => 'image',
    'post_status' => null,
    'numberposts' => -1
    );
    $attachments2 = get_posts($args2);
    ?>

    I manually entered the page_id and it pulls the attachments from a different page. I would love to be able to have it pull attachments from multiple pages. The "post_parent" looks like the only line of concern, I just don't know how the specifics for multiple IDs there

Topic Closed

This topic has been closed to new replies.

About this Topic