I have a list of articles on my website.

Some of the articles are post types with the "Article" category and others are PDF files uploaded to the media library, also with the "Article" category. I added categories to the media library using these functions in functions.php:

// add categories for attachments
function add_categories_for_attachments() {
    register_taxonomy_for_object_type( 'category', 'attachment' );
add_action( 'init' , 'add_categories_for_attachments' );

// add tags for attachments
function add_tags_for_attachments() {
    register_taxonomy_for_object_type( 'post_tag', 'attachment' );
add_action( 'init' , 'add_tags_for_attachments' );

thanks to this article.

I need to display a single category page which lists both types of posts (media and regular posts).

Is there a simple way to achieve it?

2 Answers 2


Something like this should work :

$args = array ( 'post_type' => array( 'post', 'attachment'), 'category' => ARTICLE_CATID   );
$query = new WP_Query( $args );
  • Thank you. That really helped me find the complete answer: $args = array('category' => $wp_query->get_queried_object_id(), 'posts_per_page' => -1, 'orderby'=> 'title', 'order' => 'ASC' , 'post_type' => array( 'post', 'attachment'),'post_status' => array( 'publish', 'inherit')); $glossaryposts = get_posts( $args ); Commented Jun 9, 2019 at 17:04
  • why not mark it as the answer then? Commented Jun 9, 2019 at 18:09
  • I have to say that I am not sure which answer to mark as the answer. Yours or mine. Commented Jun 13, 2019 at 7:49

Thanks to @bjornredemption, I used the following code snippet:

$args = array('category' => $wp_query->get_queried_object_id(), 'posts_per_page' => -1, 'orderby'=> 'title', 'order' => 'ASC', 'post_type' => array( 'post', 'attachment'),'post_status' => array( 'publish', 'inherit'));
$glossaryposts = get_posts( $args );

Furthermore the function have_posts() must be changed because the default one does not check for attachments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.