Support

Account

Home Forums Feature Requests Speed up work with new option in gallery field Reply To: Speed up work with new option in gallery field

  • I tried to put it in gallery.php, and functions.php, but suppose problem might lie here

    <?php
    
    add_filter( 'post_gallery', 'authentic_post_gallery', 10, 3 );
    
    function authentic_post_gallery( $output = '', $atts, $instance ) {
    
      $post = get_post();
    
      $default = array(
        'id'         => $post ? $post->ID : 0,
        'order'      => 'ASC',
        'orderby'    => 'menu_order ID',
        'columns'    => 3,
        'size'       => 'thumbnail',
      );
    
      $atts = array_merge($default, $atts);
    
      $id = intval( $atts['id'] );
    
      if ( ! empty( $atts['include'] ) ) {
        $_attachments = get_posts( array( 'include' => $atts['include'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) );
    
        $attachments = array();
        foreach ( $_attachments as $key => $val ) {
          $attachments[$val->ID] = $_attachments[$key];
        }
      } elseif ( ! empty( $atts['exclude'] ) ) {
        $attachments = get_children( array( 'post_parent' => $id, 'exclude' => $atts['exclude'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) );
      } else {
        $attachments = get_children( array( 'post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) );
      }
    
      if ( empty( $attachments ) ) {
        return '';
      }
    
      $selector = "gallery-{$instance}";
    
      if (isset($atts['layout'])) {
    
        $layout = $atts['layout'];