/** * This forces the attachments to be fetched using the correct ordering. * Some plugins / themes override this globally for some reason, so this is a preventative measure to ensure sorting is correct * @param $query WP_Query */ public function force_gallery_ordering($query) { //only care about attachments if (array_key_exists('post_type', $query->query) && 'attachment' === $query->query['post_type']) { $query->set('orderby', foogallery_sorting_get_posts_orderby_arg($this->sorting)); $query->set('order', foogallery_sorting_get_posts_order_arg($this->sorting)); } }
/** * Lazy load the attachments for the gallery * * @return array */ public function galleries() { //lazy load the attachments for performance if ($this->_galleries === false) { $this->_galleries = array(); if (!empty($this->gallery_ids)) { $gallery_query_args = apply_filters('foogallery_album_gallery_get_posts_args', array('post_type' => FOOGALLERY_CPT_GALLERY, 'posts_per_page' => -1, 'post__in' => $this->gallery_ids, 'orderby' => foogallery_sorting_get_posts_orderby_arg($this->sorting), 'order' => foogallery_sorting_get_posts_order_arg($this->sorting))); $galleries = get_posts($gallery_query_args); $this->_galleries = array_map(array('FooGallery', 'get'), $galleries); } } return $this->_galleries; }