WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. micks800
    Member
    Posted 1 year ago #

    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 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/

  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
    Member
    Plugin Author

    Posted 1 year 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

About this Topic

Tags

No tags yet.