/** * Get posts * * This can optionally be used by the template. * $this->instance is sanitized before being made available here. * * @since 0.9 * @return array Posts for widget template */ function ctfw_get_posts() { $posts = array(); // Base arguments $args = array('post_type' => 'attachment', 'post_status' => 'inherit', 'post_mime_type' => 'image', 'posts_per_page' => $this->ctfw_instance['limit'], 'orderby' => $this->ctfw_instance['orderby'], 'order' => $this->ctfw_instance['order'], 'no_found_rows' => true); // All Galleries - get images attached to Gallery posts/pages if ('all' == $this->ctfw_instance['post_id'] || empty($this->ctfw_instance['post_id'])) { $args['post_parent__in'] = ctfw_gallery_posts_ids(); // get all Gallery post IDs into array } else { // Get data for one post $posts = ctfw_gallery_posts(array('post_id' => $this->ctfw_instance['post_id'])); // Use ID's from shortcode attributes if (!empty($posts[$this->ctfw_instance['post_id']]['image_ids'])) { $args['post__in'] = $posts[$this->ctfw_instance['post_id']]['image_ids']; } } // Get gallery images if (!empty($args['post_parent__in']) || !empty($args['post__in'])) { // if have something to search for $images_query = new WP_Query($args); $posts = !empty($images_query->posts) ? $images_query->posts : array(); } // Return filtered return apply_filters('ctfw_gallery_widget_get_posts', $posts); }
/** * Get posts * * This can optionally be used by the template. * $this->instance is sanitized before being made available here. * * @since 0.9 * @return array Posts for widget template */ function ctfw_get_posts() { // Get gallery pages/posts $posts = ctfw_gallery_posts(array('order' => $this->ctfw_instance['order'], 'orderby' => $this->ctfw_instance['orderby'], 'limit' => $this->ctfw_instance['limit'])); // Return filtered return apply_filters('ctfw_galleries_widget_get_posts', $posts); }
/** * Get gallery posts IDs * * Get IDs of all pages/posts with gallery content. * * @since 0.9 * @param array $options Options for getting gallery posts IDs * @return array Posts IDs */ function ctfw_gallery_posts_ids($options = array()) { // Do not extract data in this case, just need IDS $options['extract_data'] = false; // optimization // Get posts/pages with IDs $gallery_posts = ctfw_gallery_posts($options); // Put IDs into array $ids = array_keys($gallery_posts); // Return filtered return apply_filters('ctfw_gallery_posts_ids', $ids); }