WordPress.org

Forums

Enhanced Media Library
[resolved] API (2 posts)

  1. mtissington
    Member
    Posted 1 year ago #

    Using php, how can I get a list of images (or media) that belong to a particular tax and category?

    https://wordpress.org/plugins/enhanced-media-library/

  2. webbistro
    Member
    Plugin Author

    Posted 1 year ago #

    Something like this:

    <?php 
    
    $args = array (
    	'post_type' => 'attachment',
    	'post_status' => 'any',
    	'posts_per_page' => -1,
    	'tax_query' => array(
    		'relation' => 'AND',
    		array(
    			'taxonomy' => 'YOUR_TAXONOMY_NAME',
    			'field' => 'slug',
    			'terms' => 'YOUR_TAXONOMY_TERM_NAME'
    		),
    		array(
    			'taxonomy' => 'category',
    			'field' => 'slug',
    			'terms' => 'YOUR_CATEGORY_NAME'
    		)
    	)
    );
    $the_query = new WP_Query( $args );
    
    if ( $the_query->have_posts() ) :
    
    	while ( $the_query->have_posts() ) : $the_query->the_post(); 
    
                echo wp_get_attachment_image( get_the_ID(), "thumbnail");
    
          endwhile; 
    
    endif;
    
    wp_reset_postdata(); 
    
    ?>

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Enhanced Media Library
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.