Title: Solution: Add number attribute to shortcode
Last modified: August 21, 2016

---

# Solution: Add number attribute to shortcode

 *  [micks800](https://wordpress.org/support/users/micks800/)
 * (@micks800)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/solution-add-number-attribute-to-shortcode/)
 * Hi,
    As lot of other user’s requested, we also noticed that this amazing plugin
   was missing the ‘number’ attribute in the shortcode which was limiting it’s functionality.
   We have patched the code (I wish we had access to source code so that we could
   patch it as well) to make it working and here’s the solution for everyone else–
 * If you are using V1.4, just replace two functions with the following:
 * _[ Moderator Note: [Please post code](http://codex.wordpress.org/Forum_Welcome#Posting_Code)
   or markup snippets between backticks or use the code button. ]_
 *     ```
       // Get media_tags from database
       	function media_tags_query($term, $size, $number) {
       		$pattern = "/\d\,\s?\d/";
   
       		if (strrpos($term, ',') !== false) {
       			$term = explode(',', $term);
       		}
       		if ( preg_match($pattern, $size) ) {
       			$size = array($size);
       		}
       		if ( preg_match($pattern, $number) ) {
       			$number = array($number);
       		}
   
       		$args = array(
       			'post_type' => 'attachment',
       			'post_mime_type' => 'image',
       			'post_status' => 'inherit',
       			'posts_per_page' => $number,
       			'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 .= '<a rel="lightbox[roadtrip]" title="'.get_the_title().'" href="'.$url.'">'.$image.'</a>'."\n";
       		endwhile;
   
       		return $output;
       	}
   
       	// Function for shortcode
       	function media_tags_shortcode($atts) {
       		extract( shortcode_atts( array(
       			'name' => '',
       			'size' => 'thumbnail',
       			'number' => '-1',
       		), $atts ) );
       		return self::media_tags_query($name, $size, $number);
       	}
       ```
   
 * For other versions, just use the above as reference and manually apply the patch.
 * Cheers,
    Mick
 * [http://wordpress.org/extend/plugins/wordpress-media-tags/](http://wordpress.org/extend/plugins/wordpress-media-tags/)

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Moderator [Jan Dembowski](https://wordpress.org/support/users/jdembowski/)
 * (@jdembowski)
 * Forum Moderator and Brute Squad
 * [12 years, 11 months ago](https://wordpress.org/support/topic/solution-add-number-attribute-to-shortcode/#post-3883823)
 * Have you tried contacting the author regarding your contribution? If you follow
   the plugin page to his homepage you should see a Contact link at the top.
 *  Plugin Author [Philipp Speck](https://wordpress.org/support/users/destio/)
 * (@destio)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/solution-add-number-attribute-to-shortcode/#post-3883976)
 * Sometimes I read what’s going on here, haha! WordPress Media Tags 1.5 is coming
   now! Tataa!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Solution: Add number attribute to shortcode’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/wordpress-media-tags.svg)
 * [WordPress Media Tags](https://wordpress.org/plugins/wordpress-media-tags/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wordpress-media-tags/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wordpress-media-tags/)
 * [Active Topics](https://wordpress.org/support/plugin/wordpress-media-tags/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wordpress-media-tags/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wordpress-media-tags/reviews/)

 * 2 replies
 * 3 participants
 * Last reply from: [Philipp Speck](https://wordpress.org/support/users/destio/)
 * Last activity: [12 years, 11 months ago](https://wordpress.org/support/topic/solution-add-number-attribute-to-shortcode/#post-3883976)
 * Status: not resolved