WordPress Media Tags
Solution: Add number attribute to shortcode (3 posts)

  1. micks800
    Posted 3 years ago #

    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 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(
    						'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";
    		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.



  2. 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.

  3. Philipp Speck
    Plugin Author

    Posted 3 years ago #

    Sometimes I read what's going on here, haha! WordPress Media Tags 1.5 is coming now! Tataa!

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WordPress Media Tags
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.