animasola
Member
Posted 6 months 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!
animasola
Member
Posted 6 months ago #
Regarding the return, I meant an array of arrays/objects or attachment/post ids
animasola
Member
Posted 6 months ago #
I seemed to have found it, it returns an array of attachment objects. Here it is for anyone whoever needs it as well:
Here is the function I created:
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;
}
proximity2008
Member
Posted 4 months ago #
Thanks for sharing - I've tried your function. What is the function web_get_blog_id()? WordPress complains it doesn't exist.
Using WordPress 2.8