The MU forums have moved to WordPress.org

displaying all attachments (4 posts)

  1. animasola
    Member
    Posted 14 years ago #

    Which Wordpress function displays or returns all post IDs of all media attachments within a certain blog? Or if there isn't one, can anyone help me find a combination of functions which would do these? Ideally I want to retrieve all media attachments for a specific blog, so I'd want my argument/parameter to be the blog id and the return to be an array/object of the details of the attachment or at least the attachment/post id.

    Any piece of advice would be highly appreciated, thanks!

  2. animasola
    Member
    Posted 14 years ago #

    Regarding the return, I meant an array of arrays/objects or attachment/post ids.

  3. andrea_r
    Moderator
    Posted 14 years ago #

    Post attachments are saved in the database as post, but with a type of "attachment". Can't remember the field name off the top of my head, but if you look in the wp_X_posts table, and compare an actual post to a post attachment, it's pretty clear.

    So then your pseudo-SQL statement would be something like

    SELECT blog_id WHERE post_type IS 'attachment'

  4. animasola
    Member
    Posted 14 years ago #

    thanks andrea, I actually found this out a few hours after I posted this but I forgot. For anyone who might need it, here is what I used:

    `global $wpdb;
    if(!is_numeric($blog_id)) {
    $blog_id = web_get_blog_id($blog_id);
    }
    $wpdb->set_blog_id($blog_id, 1);

    $args = array(
    'post_type' => 'attachment',
    'post_mime_tyupe' => 'image'
    );

    if( !$attachments = get_children($args) ) {
    return false;
    } else {
    return $attachments;
    }`

About this Topic

  • Started 14 years ago by animasola
  • Latest reply from animasola