title: Creating URL to prefiltered image gallery (without success)
body: <p>I'm using this wordpress plugin to create an image gallery with buttoms filters (based on categories) - Here the gallery: <a href="http://185.56.87.172/~canaryfi/locations-all/" rel="nofollow noreferrer">http://185.56.87.172/~canaryfi/locations-all/</a></p>
  
  <p>The gallery works awesome, when you click on a button, the images are automatically sorted.</p>
  
  <p>I am trying to create links from other pages to this gallery for some categories and that when loading the page, only appear those categories</p>
  
  <p>Example: <a href="http://185.56.87.172/~canaryfi/locations-all/#city" rel="nofollow noreferrer">http://185.56.87.172/~canaryfi/locations-all/#city</a> to show the same gallery filtered by cities or /#desert to show deserts</p>
  
  <p>I tried to modify the isotope, the category name, the PHP and I spend 2 days reading several articles in several blogs and developer webpage, even I read all those articles here:</p>
  
  <p><a href="https://stackoverflow.com/questions/10562283/isotope-filter-to-link-from-another-page">isotope filter to link from another page</a></p>
  
  <p><a href="https://stackoverflow.com/questions/17620097/apply-data-filter-on-a">Apply data-filter on &lt;a&gt;</a></p>
  
  <p><a href="https://github.com/metafizzy/isotope/issues/688" rel="nofollow noreferrer">https://github.com/metafizzy/isotope/issues/688</a></p>
  
  <p>and much more :(</p>
  
  <p>so my last chance is ask you</p>
  
  <p>Can you please support me? Many thanks in advance for you support</p>
  
  <pre><code>&lt;?php
  /**
   * Plugin Name: Go Gallery
   * Plugin URI:  https://wordpress.org/plugins/go-gallery/
   * Text Domain: go_gallery
   * Description: Responsive filterable gallery with media categories. Easy to use, lightweight yet powerful shortcode driven gallery plugin to display beautiful galleries without slowing down your page.
   * Version:     1.0
   * Author:      AlViMedia
   * Author URI:  http://alvimedia.com
   * License:     GPL
   */
  
  if ( ! defined( 'ABSPATH' ) ) {
      exit;
  }
  
  define('GO_GALLERY_VERSION', '1.0');
  
  add_action('wp_enqueue_scripts', 'go_gallery_enqueue_scripts');
  
  if ( is_admin() ) {
      add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'my_plugin_action_links' );
  }
  function my_plugin_action_links( $links ) {
      $links[] = '&lt;br /&gt;&lt;br /&gt;&lt;a target="_blank" href="http://AlViMedia.com/"&gt;&lt;u&gt;&lt;strong&gt;More PlugIns by AlViMedia&lt;/strong&gt;&lt;/u&gt;&lt;/a&gt;';
      return $links;
  }
  
  function go_gallery_enqueue_scripts() {
  
      wp_enqueue_script('imagesloaded', plugins_url('/assets/plugins/imagesloaded/imagesloaded.pkgd.min.js', __FILE__), array('jquery'), GO_GALLERY_VERSION, true);
      wp_enqueue_script('isotope', plugins_url('/assets/plugins/isotope/isotope.pkgd.min.js', __FILE__), array('jquery'), GO_GALLERY_VERSION, true);
  
      wp_enqueue_script('go-gallery', plugins_url('/assets/js/gallery.js', __FILE__), array('jquery', 'isotope', 'imagesloaded'), GO_GALLERY_VERSION, true);
      wp_enqueue_style('go-gallery', plugins_url('/assets/css/gallery.css', __FILE__), null, GO_GALLERY_VERSION);
  
      wp_enqueue_script('tos', plugins_url('/assets/plugins/tos/js/jquery.tosrus.min.custom.js', __FILE__), array('jquery'), GO_GALLERY_VERSION, true);
      wp_enqueue_style('tos', plugins_url('/assets/plugins/tos/css/jquery.tosrus.custom.css', __FILE__), null, GO_GALLERY_VERSION);
  
  }
  
  /**
   * Setup Taxonomies
   * Creates 'attachment_tag' and 'attachment_category' taxonomies.
   * Enhance via filter `ct_attachment_taxonomies`
   *
   * @uses    register_taxonomy, apply_filters
   * @since   1.0.0
   * @return  void
   */
  function go_setup_taxonomies() {
  
      $labels = array(
          'name'              =&gt; _x('Media Categories', 'taxonomy general name', 'go_gallery'),
          'singular_name'     =&gt; _x('Media Category', 'taxonomy singular name', 'go_gallery'),
          'search_items'      =&gt; __('Search Media Categories', 'go_gallery'),
          'all_items'         =&gt; __('All Media Categories', 'go_gallery'),
          'parent_item'       =&gt; __('Parent Media Category', 'go_gallery'),
          'parent_item_colon' =&gt; __('Parent Media Category:', 'go_gallery'),
          'edit_item'         =&gt; __('Edit Media Category', 'go_gallery'),
          'update_item'       =&gt; __('Update Media Category', 'go_gallery'),
          'add_new_item'      =&gt; __('Add New Media Category', 'go_gallery'),
          'new_item_name'     =&gt; __('New Media Category Name', 'go_gallery'),
          'menu_name'         =&gt; __('Media Categories', 'go_gallery'),
      );
  
      $args = array(
          'hierarchical'      =&gt; TRUE,
          'labels'            =&gt; $labels,
          'show_ui'           =&gt; TRUE,
          'show_admin_column' =&gt; TRUE,
          'query_var'         =&gt; TRUE,
          'rewrite'           =&gt; TRUE,
      );
  
      register_taxonomy('attachment_category', 'attachment',  $args );
  
  }
  
  add_action('init', 'go_setup_taxonomies');
  
  
  /** Add a category filter to images */
  /*
  function go_add_image_category_filter() {
      $screen = get_current_screen();
      if ( 'upload' == $screen-&gt;id ) {
          $dropdown_options = array( 'show_option_all' =&gt; __( 'View all categories', 'ct' ), 'taxonomy' =&gt; 'attachment_category', 'hide_empty' =&gt; false, 'hierarchical' =&gt; true, 'orderby' =&gt; 'name', );
          wp_dropdown_categories( $dropdown_options );
      }
  }
  add_action( 'restrict_manage_posts', 'go_add_image_category_filter' );
  */
  
  add_shortcode('go_gallery', 'go_gallery_shortcode');
  
  function go_gallery_bool($value){
      return ($value == 'yes' || $value == 'on' || $value == '1');
  }
  
  function go_gallery_hex2rgb($hex, $alpha = '0.4') {
      $hex = str_replace("#", "", $hex);
  
      if(strlen($hex) == 3) {
          $r = hexdec(substr($hex,0,1).substr($hex,0,1));
          $g = hexdec(substr($hex,1,1).substr($hex,1,1));
          $b = hexdec(substr($hex,2,1).substr($hex,2,1));
      } else {
          $r = hexdec(substr($hex,0,2));
          $g = hexdec(substr($hex,2,2));
          $b = hexdec(substr($hex,4,2));
      }
      $rgb = array($r, $g, $b);
      return 'rgba(' . join(', ', $rgb) . ', ' . $alpha .')';
  }
  
  function go_gallery_shortcode($atts, $content = null) {
      $atts = shortcode_atts(array(
          'cat'               =&gt; '',
          'menu_show'         =&gt; '1',
          'menu_pos'          =&gt; 'center',
          'lightbox'          =&gt; 'yes',
          'limit'             =&gt; 20,
          'border_size'       =&gt; 5,
          'border_color'      =&gt; '#fff',
          'overlay_color'     =&gt; '#fff',
          'menu_button'       =&gt; 'all',
          'menu_color'        =&gt; '#fff',
          'menu_bg'           =&gt; '#000',
          'menu_bg_hover'     =&gt; '#aaa',
          'menu_gap'          =&gt; 4,
          'hover_data'        =&gt; 'yes',
          'bg'                =&gt; '#eee',
          'desc_color'        =&gt; '#000',
          'gap'               =&gt; 10,
          'style'             =&gt; 'normal',
          'size'              =&gt; 'medium'
      ), $atts, 'go_gallery');
  
      $output = '';
  
      $args = array(
          'post_type'         =&gt; 'attachment',
          'post_status'       =&gt; 'inherit',
          'posts_per_page'    =&gt; $atts['limit'],
          'order'             =&gt; 'DESC',
          'orderby'           =&gt; 'modified',
          'post_mime_type'    =&gt; 'image/jpeg,image/gif,image/jpg,image/png'
      );
  
      $categories = array();
  
      $atts['cat'] = array_map('sanitize_title', explode(',', $atts['cat']));
  
      foreach ( $atts['cat'] as $category ) {
  
          if ( $term = get_term_by('slug', $category, 'attachment_category') ) {
              $categories[$term-&gt;term_id] = $term;
          }
  
      }
  
      if ( !empty($categories) ) {
          $args['tax_query'] = array(
              array(
                  'taxonomy'  =&gt; 'attachment_category',
                  'field'     =&gt; 'term_id',
                  'terms'     =&gt; array_keys($categories)
              )
          );
      }
  
      $atts['menu_gap'] = min($atts['menu_gap'], 100);
  
      $classes[] = 'go-gallery';
      $classes[] = 'menu-' . $atts['menu_pos'];
      $classes[] = go_gallery_bool($atts['menu_show']) ? 'menu-show' : '';
      $classes[] = 'size-' . $atts['size'];
      $classes[] = 'style-' . $atts['style'];
  
      $attributes = array();
      $attributes['class'] = join(' ', $classes);
      $attributes['id'] = 'go-' . substr(md5(mt_rand(0, PHP_INT_MAX)), 0, 6);
      $attributes['data-gap'] = intval($atts['gap']);
      $attributes['data-border-color'] = $atts['border_color'];
      $attributes['data-lightbox'] = go_gallery_bool($atts['lightbox']) ? 'yes' : 'no';
      $attributes['data-desc-color'] = $atts['desc_color'];
      $attributes['data-menu-color'] = $atts['menu_color'];
      $attributes['data-menu-bg'] = $atts['menu_bg'];
      $attributes['data-menu-bg-hover'] = $atts['menu_bg_hover'];
      $attributes['data-menu-gap'] = $atts['menu_gap'];
      $attributes['data-bg'] = $atts['bg'];
      $attributes['data-border-size'] = $atts['border_size'];
      $attributes['data-overlay-color'] = go_gallery_hex2rgb($atts['overlay_color']);
  
      $thumb_size = 'medium';
  
      if ( $atts['size'] == 'large' || ($atts['style'] == 'squared' &amp;&amp; in_array($atts['size'], array('medium', 'large'))) ) {
          $thumb_size = 'large';
      }
  
      foreach ( $attributes as $attribute =&gt; $value ) {
          $attributes[$attribute] = $attribute . '="' . $value . '"';
      }
  
      $query = new WP_Query($args);
  
      $output .= '&lt;div ' . join(' ', $attributes) . '&gt;';
      $output .= '&lt;ul class="go-gallery-filters"&gt;';
      $output .= '&lt;li&gt;';
      $output .= '&lt;a data-filter="" href="#"&gt;' . __($atts['menu_button'], 'go_gallery') . '&lt;/a&gt;';
      $output .= '&lt;/li&gt;';
  
      foreach ( $categories as $category ) {
  
          if ( !empty($category) ) {
              $output .= '&lt;li&gt;';
              $output .= '&lt;a data-filter="' . $category-&gt;slug . '" href="#"&gt;' . $category-&gt;name . '&lt;/a&gt;';
              $output .= '&lt;/li&gt;';
  
          }
  
      }
  
  
      $output .= '&lt;/ul&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;';
  
      $output .= '&lt;div class="go-gallery-list-wrapper"&gt;';
      $output .= '&lt;ul class="go-gallery-list"&gt;';
  
      foreach ( $query-&gt;posts as $post ) {
  
          $category_terms = wp_get_post_terms($post-&gt;ID, 'attachment_category');
  
          $classes = array();
          $classes[] = 'go-gallery-item';
  
          foreach ( $category_terms as $category_term ) {
              $classes[] = 'category-' . $category_term-&gt;slug;
          }
  
          $image_source = wp_get_attachment_image_src($post-&gt;ID, 'full');
  
          $output .= '&lt;li data-source="' . $image_source[0] . '" class="' . join(' ', $classes) . '"&gt;';
  
          $output .= '&lt;a class="image-wrap" href="' . $image_source[0] . '"&gt;';
          $output .= '&lt;figure&gt;';
  
          $output .= wp_get_attachment_image($post-&gt;ID, $thumb_size);
  
          $output .= '&lt;div class="image-overlay"&gt;';
  
          if ( go_gallery_bool( $atts['hover_data'] ) ){
              $output .= '&lt;h3&gt;' . $post-&gt;post_title . '&lt;/h3&gt;';
              $output .= '&lt;h4&gt;' . $post-&gt;post_content . '&lt;/h4&gt;';
          }
  
          $output .= '&lt;/div&gt;';
  
          $output .= '&lt;/figure&gt;';
          $output .= '&lt;/a&gt;';
          $output .= '&lt;/li&gt;';
      }
  
      $output .= '&lt;/ul&gt;';
      $output .= '&lt;/div&gt;';
      $output .= '&lt;/div&gt;';
  
      return $output;
  }
  </code></pre>