1

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...

1

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.

  • 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
1

Try get_terms function

Here is an example use (from Codex):

$categories = get_terms( 'category', array(
    'orderby'    => 'count',
    'hide_empty' => 0
) );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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