When I filter media library to display only the images I want to include in a gallery (by a shortcode needing images id), it would be very useful if Wordpress showed somewhere a list of the ids of the displayed images. Currently I open images one by one to retrieve their id, and I feel this should not be the right way to do it.
Since I'm a Wordpress newbie, it might exist a different way to achieve the same result, such a plugin that I was not able to find, but anyway the functionality I described above (which I have not idea how to achieve) would solve the problem, and I think it would be very useful to many.
Thanks in advance.
Follow up
Building on Sunil Dora answer I wrote this snippet which allows to select images by one or more (by AND operator) category terms and use an existing shortcode to create a gallery (in the example below a Shortcode Ultimate plugin shortcode is created and executed, but you can tailor the snippet to build any kind of shortcode you want). I believe this functionality is very powerful because you don't have to modify your shortcodes to update your galleries, but you only have to assign the right category terms to attachments. For example if you want to add an image to a gallery, you don't have to edit the shortcode but just upload the new image and assign the right category terms to it. Here is the snippet, I inserted it at the end of my funtions.php
, I hope someone is able to build a simple plugin with it and notify that here.
// usage: [mmj-taximids categoryname='media_category' categoryterms='term1,term2,term3']
// usage: [mmj-taximids size=120 categoryname='media_category' categoryterms='term1,term2,term3']
add_shortcode('mmj-taximids', 'mmj_taxonomy_image_ids');
function mmj_taxonomy_image_ids($atts)
{
// Attributes
$a = shortcode_atts(array(
'categoryname' => 'not_provided',
'categoryterms' => 'not_provided',
'limit' => -1,
'size' => 180
), $atts);
// Output Code
$tax_query_array = array();
foreach (explode(',', $a['categoryterms']) as $value) {
array_push($tax_query_array,array(
'taxonomy' => $a['categoryname'],
'field' => 'slug',
'terms' => array($value)
));
}
if (count($a)>1) {$tax_query_array["relation"]="AND";}
//print_r($tax_query_array);
$args = array(
'post_type' => 'attachment',
'post_status' => 'any',
'post_mime_type' => array( 'image/jpeg','image/gif','image/png','image/bmp','image/tiff','image/x-icon' ),
'posts_per_page' => -1,
'tax_query' => $tax_query_array
);
$query_images = new WP_Query($args);
$id_list = "";
foreach ($query_images->posts as $image) {
$id_list .= (($image->ID) . ",");
}
return do_shortcode("[su_custom_gallery source=\"media: ".$id_list."\" limit=".$a['limit']." link=\"lightbox\" width=\"".$a['size']."\" height=\"".$a['size']."\"][/su_custom_gallery]");
}