Oxylis
Oxylis

Reputation: 13

wordpress Get all media from a category

Is there function like get_attached_media but for categories? http://codex.wordpress.org/Function_Reference/get_attached_media

I've assigned my images categories with:

function wptp_add_categories_to_attachments() { register_taxonomy_for_object_type( 'category', 'attachment' ); } add_action( 'init' , 'wptp_add_categories_to_attachments' );

And all I need to do is to list images in a category.

Edit: To clarify, I have my category page which has tabs, one listing articles, one listing some category taxonomy informations and one which will display a list of images. These images are assigned to the category but I do not know the function to pull the list of images from the category.

Upvotes: 0

Views: 3222

Answers (1)

user488187
user488187

Reputation:

You can get attachments just like any other type of post. So,

$args = array(
    'category' => $cat_ID or
    'category_name' => $cat_name,
    'post_type' => 'attachment'
);

$attachments = get_posts($args);

Upvotes: 1

Related Questions