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

I want to make custom taxonomy (gallery) and terms (name1, name2, name3...) Add images into media tab and then retrieve all images from same term. Look like simple task, but I cant manage it.

I registered new (custom) tax, added some terms to image, but I cannot retrieve any of them. Searched for two days for solution, just can't put all pieces all together.

I want to get list of terms first, and then get list of images from this list.

share|improve this question

To get all images from the same term you can use WP_Query with the "tax_query" argument:

$args = array(
    'post_status' => 'inherit',
'posts_per_page' => -1,
'post_type' => 'attachment',

$args['tax_query'] = array(
    'taxonomy' => 'YOUR_CUSTOM_TAXONOMY',
    'terms' => array( 'YOUR_CUSTOM_TAXONOMY_TERM' ),
    'field' => 'slug',

$the_query = new WP_Query( $args );

if ( $the_query->have_posts() ) {
    while ( $the_query->have_posts() ) {
        // DO SOMETHING

/* Restore original Post Data */
share|improve this answer

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.