su_get_gallery_slides_posts

The shortcodes-ultimate su get gallery slides posts function.

Published Date - February 15, 2021

Description

Auxilary function to query posts to be used in a gallery.

su_get_gallery_slides_posts( $atts );

Parameters

  1. $atts


Usage

The following example is for adding a hook callback.

if ( !function_exists( 'su_get_gallery_slides_posts' ) ) {
    require_once ABSPATH . PLUGINDIR . 'shortcodes-ultimateshortcodes-ultimate/includes/functions-galleries.php';
}

// The input(s). 
$atts = null;

// NOTICE! Understand what this does before running.
$result = su_get_gallery_slides_posts( $atts );
            

Defined

The function is defined in the following location(s).

shortcodes-ultimate/includes/functions-galleries.php

function su_get_gallery_slides_posts( $atts ) {

	$source = su_parse_images_source( $atts['source'] );

	if ( ! $source ) {
		return false;
	}

	if ( 'media' === $source['type'] ) {

		$query['post_mime_type'] = 'image/jpeg,image/gif,image/jpg,image/png';
		$query['post_type']      = 'attachment';
		$query['post_status']    = 'inherit';

		if ( 'recent' === $source['ids'] ) {
			$query['posts_per_page'] = $atts['limit'];
		}

		if ( 'recent' !== $source['ids'] ) {

			$query['posts_per_page'] = -1;
			$query['post__in']       = $source['ids'];
			$query['orderby']        = 'post__in';

		}

	}

	if ( 'posts' === $source['type'] ) {

		$query['post_type'] = 'any';
		$query['meta_key']  = '_thumbnail_id';

		if ( 'recent' === $source['ids'] ) {
			$query['posts_per_page'] = $atts['limit'];
		}

		if ( is_array( $source['ids'] ) ) {

			$query['ignore_sticky_posts'] = true;
			$query['posts_per_page']      = count( $source['ids'] );
			$query['post__in']            = $source['ids'];
			$query['orderby']             = 'post__in';

		}

	}

	if ( 'taxonomy' === $source['type'] ) {

		if ( ! $source['tax'] ) {
			return array();
		}

		$query['tax_query']      = array(
			array(
				'taxonomy' => $source['tax'],
				'terms'    => $source['ids'],
				'field'    => 'id',
			),
		);
		$query['post_type']      = 'any';
		$query['posts_per_page'] = $atts['limit'];
		$query['meta_key']       = '_thumbnail_id';

		if ( su_is_media_taxonomy( $source['tax'] ) ) {

			$query['post_mime_type'] = 'image/jpeg,image/gif,image/jpg,image/png';
			$query['post_type']      = 'attachment';
			$query['post_status']    = 'inherit';
			$query['meta_key']       = null;

		}

	}

	if ( 'yes' === $atts['random'] ) {
		$query['orderby']             = 'rand';
		$query['ignore_sticky_posts'] = true;
	}

	$query = apply_filters( 'su/get_gallery_slides_query', $query, $source, $atts );
	$query = new WP_Query( $query );

	return isset( $query->posts ) ? $query->posts : array();

}