WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Essentially, I build web sites with galleries, for photographers. Up until now, gallery images have all been attached to posts and I've just pulled from the category taxonomy. This is messy if it's also to be used as a regular blog.

So I've been poking around and I discovered things like if an attachment item isn't assigned to a post, it has a parent_post ID of 0.

If I could, how would I go about simply getting all items with a term in my custom taxonomy, ignoring their parent_post IDs?

I'm getting the feeling Wordpress just isn't quite there yet, for what I would like to do...

share|improve this question
up vote 1 down vote accepted

If I understand right, you need all attachments (attached or not) with specified term?

$args = array(
    'post_type'     => 'attachment',
    'my_taxonomy' => 'my_taxonomy_term'

$my_query = new WP_Query( $args );

if( $my_query->have_posts() ):
    while ($my_query->have_posts()) : $my_query->the_post();

        // your stuff here

// Don't forget to reset

WP_Query Taxonomy Parameters.

share|improve this answer
I don't know where you went wrong, or where I was going wrong extending your code... But I couldn't get it to work. But your logic I agreed with so I did some more digging over at the codex and found codex.wordpress.org/Template_Tags/… THANKS :) – Thomas Chapman Feb 2 '13 at 16:10

Try get_terms function

Here is an example use (from Codex):

$categories = get_terms( 'category', array(
    'orderby'    => 'count',
    'hide_empty' => 0
) );
share|improve this answer
I've realised I wasn't being clear! I don't want the terms, I want the items with a particular term. From what I understand, I'd have to use a loop to catch all of the attachment items with and without posts attached. codex.wordpress.org/Function_Reference/get_the_term_list – Thomas Chapman Feb 1 '13 at 15:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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