Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

2 Answers

up vote 0 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

    endwhile;
}
// Don't forget to reset
wp_reset_postdata();

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
add comment

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
add comment

Your Answer

 
discard

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.