Title: get_posts assistance needed
Last modified: August 19, 2016

---

# get_posts assistance needed

 *  [candlebain](https://wordpress.org/support/users/candlebain/)
 * (@candlebain)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/get_posts-assistance-needed/)
 * I’m trying to use get_posts() to get a list of attachments for a College Class
   sub-page I’ve built. To organize things, I’m using Categories to identify posts
   dealing with the College Class, and then I’ve built a Custom Category Template
   for it.
 * Here’s the problem:
 * get_posts() doesn’t appear to be accepting the ‘category_name’ argument. I may
   be using it wrong, so here’s my code:
 *     ```
       <?php
   
       $args = array(
       	'post_type' => 'attachment',
       	'category_name' => 'rock-history',
       	'numberposts' => -1,
       	'post_status' => null,
       	'post_parent' => null, // any parent
       	);
       $attachments = get_posts($args);
       if ($attachments) {
       	foreach ($attachments as $post) {
       		setup_postdata($post);
       		the_title();
       		the_attachment_link($post->ID, false);
       		the_excerpt();
       	}
       }
   
       ?>
       ```
   
 * Without the ‘category_name’ argument, everything shows from the entire site. 
   With it, nothing shows…including attachments from posts that have the category
   tag applied.
 * Do Slugs need to be done with any special formatting? Any suggestions on how 
   to get this to work?
 * Thanks in advance.

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [lindsayanng](https://wordpress.org/support/users/lindsayanng/)
 * (@lindsayanng)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/get_posts-assistance-needed/#post-1520490)
 * This is generally what I use to pull posts from a specific category
    `<?php query_posts('
   showposts=1&cat=3') ?>`
 *  Thread Starter [candlebain](https://wordpress.org/support/users/candlebain/)
 * (@candlebain)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/get_posts-assistance-needed/#post-1520493)
 * Any tips on getting this to work though? Am I using it wrong?
 * I actually need the attachments in a single page as a repository for attachments
   from all posts related to a class. I don’t need to post text on this page. I’m
   just trying to pull all attachments from only the College Class category into
   a single page. Instead, I’m either getting every attachment from every category,
   or nothing at all.
 *  Thread Starter [candlebain](https://wordpress.org/support/users/candlebain/)
 * (@candlebain)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/get_posts-assistance-needed/#post-1520494)
 * Is it possible the slug is only associated with the text? Or is it associated
   with the media as well?
 * Any idea how I might do this?
 *  Thread Starter [candlebain](https://wordpress.org/support/users/candlebain/)
 * (@candlebain)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/get_posts-assistance-needed/#post-1520512)
 * Here’s something else I’ve tried:
 *     ```
       <?php
       	$args = array(
       				'post_type' => 'attachment',
       				'post_mime_type' => 'application/pdf'
       			);
       	$pdfs =& get_children($args);
       	print_r($pdfs);
       	foreach ( (array) $pdfs as $attachment_id => $attachment ) {
       		echo wp_get_attachment_link( $attachment_id );
       	}
       ?>
       ```
   
 * It’s not recognizing my MIME type. I was hoping this would let me sort into categories
   once I found the links…
 * Ugh.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘get_posts assistance needed’ is closed to new replies.

## Tags

 * [functions](https://wordpress.org/support/topic-tag/functions/)
 * [get_posts](https://wordpress.org/support/topic-tag/get_posts/)
 * [templates](https://wordpress.org/support/topic-tag/templates/)

 * 4 replies
 * 2 participants
 * Last reply from: [candlebain](https://wordpress.org/support/users/candlebain/)
 * Last activity: [15 years, 11 months ago](https://wordpress.org/support/topic/get_posts-assistance-needed/#post-1520512)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
