/* ========================================================================== 6. DYNAMIC MEDIA GALLERY v47 STABLE ========================================================================== */ add_shortcode('tag-gallery', function($atts) { // UPDATED: Added title parameter (default is 'on') $a = shortcode_atts( array( 'tag' => '', 'columns' => '6', 'per_page' => '48', 'search' => 'on', 'index' => 'on', 'title' => 'on' ), $atts ); if ( empty($a['tag']) ) return 'Please specify a tag.'; $tag_obj = get_term_by('slug', $a['tag'], 'post_tag'); $initial_name = ($tag_obj) ? $tag_obj->name : ucwords(str_replace('-', ' ', $a['tag'])); $images = get_posts( array( 'post_type' => 'attachment', 'post_status' => 'inherit', 'posts_per_page' => -1, 'tax_query' => array(array('taxonomy'=>'post_tag','field'=>'slug','terms'=>'original-photo')), 'fields' => 'ids' ) ); if ( empty($images) ) return 'No images found.'; $cols = intval($a['columns']); $per_page = intval($a['per_page']); $gallery_data = []; foreach ( $images as $id ) { $post = get_post($id); if (!$post) continue; $tags_raw = wp_get_post_terms($id, 'post_tag', array('fields' => 'names')); $tax_html = '
Tags: '; foreach($tags_raw as $t) { $tax_html .= ''.esc_html($t).', '; } $tax_html = rtrim($tax_html, ', ') . '
'; $gallery_data[] = array( 'url' => wp_get_attachment_url($id), 'thumb' => wp_get_attachment_image_src($id, 'thumbnail')[0], 'title' => esc_attr($post->post_title), 'cap' => esc_attr($post->post_excerpt), 'desc' => esc_attr(wp_strip_all_tags($post->post_content)), 'tax' => $tax_html, 'tags' => $tags_raw, 'search_blob' => strtolower(esc_attr($post->post_title . ' ' . $post->post_excerpt . ' ' . implode(' ', $tags_raw))) ); } $output = ''; $output .= ''; $output .= '
×
'; $output .= ''; return $output; });