WordPress.org

Ready to get started?Download WordPress

Forums

WordPress Media Tags
Get all media with certain tag (1 post)

  1. chrisnowak
    Member
    Posted 1 year ago #

    Hello,

    I needed the functionality to grab ALL media (not just pictures) and return an array of absolute urls that I could manipulate. I added another function in the class ( inserted below on line 105) based on media_tags_query.

    Returns an array of urls like

    Array (
         [0] => http://absoulteurl/item1,
         [1] => http://absoulteurl/item2,
         [2] => http://absoulteurl/item3
    )

    Usage:

    $query = wp_media_tags_plugin::all_urls_from_tags_query('flowers');
    function all_urls_from_tags_query($term, $size='thumbnail') {
    		$args = array(
    			'post_type' => 'attachment',
    			/* 'post_mime_type' => 'image', */
    			'post_status' => 'inherit',
    			'tax_query' => array(
    					array(
    						'taxonomy' => 'media_tag',
    						'terms' => $term,
    						'field' => 'slug',
    					)
    				)
    		);
    
    		$loop = new WP_Query($args);
    		while ( $loop->have_posts() ) : $loop->the_post();
    			$image = wp_get_attachment_image('', $size, false);
    			$url = wp_get_attachment_url();
    			$output[] = $url;
    		endwhile;
    
    		//if ($output) return join($output);
    		if ($output) return $output;
    		// Reset Post Data
    		wp_reset_postdata();
    	}

    http://wordpress.org/extend/plugins/wordpress-media-tags/

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.