• 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!

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

    (@animasola)

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

    Thread Starter animasola

    (@animasola)

    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;
    		}

    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

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘displaying all attachments’ is closed to new replies.