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 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,
Mickhttps://www.ads-software.com/extend/plugins/wordpress-media-tags/
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Solution: Add number attribute to shortcode’ is closed to new replies.