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.

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

1 Answer

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(
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() ) {
    $the_query->the_post();
        // DO SOMETHING
    }
}

/* Restore original Post Data */
wp_reset_postdata();
share|improve this answer
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.