From 24601d6405181ac87c7828faae95f2dc4a800911 Mon Sep 17 00:00:00 2001 From: Fellan-91 Date: Wed, 24 Apr 2024 16:21:27 +0300 Subject: [PATCH] added sort by image fields --- classes/class-admin.php | 13 +++++--- classes/class-get-portfolio.php | 53 +++++++++++++++++++++++++++++---- 2 files changed, 56 insertions(+), 10 deletions(-) diff --git a/classes/class-admin.php b/classes/class-admin.php index 4dd8e878..fb0da54d 100644 --- a/classes/class-admin.php +++ b/classes/class-admin.php @@ -1773,10 +1773,15 @@ public function register_controls() { 'group' => 'images_order', 'default' => 'default', 'options' => array( - 'default' => esc_html__( 'Default', 'visual-portfolio' ), - 'date' => esc_html__( 'Uploaded', 'visual-portfolio' ), - 'title' => esc_html__( 'Title', 'visual-portfolio' ), - 'rand' => esc_html__( 'Random', 'visual-portfolio' ), + 'default' => esc_html__( 'Default', 'visual-portfolio' ), + 'title' => esc_html__( 'Item Title', 'visual-portfolio' ), + 'description' => esc_html__( 'Item Description', 'visual-portfolio' ), + 'image_title' => esc_html__( 'Image Title', 'visual-portfolio' ), + 'caption' => esc_html__( 'Image Caption', 'visual-portfolio' ), + 'alt' => esc_html__( 'Image Alt', 'visual-portfolio' ), + 'image_description' => esc_html__( 'Image Description', 'visual-portfolio' ), + 'date' => esc_html__( 'Image Uploaded', 'visual-portfolio' ), + 'rand' => esc_html__( 'Random', 'visual-portfolio' ), ), ) ); diff --git a/classes/class-get-portfolio.php b/classes/class-get-portfolio.php index 063314ce..aca2d5e6 100644 --- a/classes/class-get-portfolio.php +++ b/classes/class-get-portfolio.php @@ -1268,12 +1268,16 @@ public static function get_query_params( $options, $for_filter = false, $layout_ // prepare titles and descriptions. foreach ( $images as $k => $img ) { $img_meta = array( - 'title' => '', - 'description' => '', - 'caption' => '', - 'alt' => '', - 'none' => '', - 'date' => '', + 'title' => '', + 'image_title' => '', + 'image_description' => '', + 'image_caption' => '', + 'image_alt' => '', + 'description' => '', + 'caption' => '', + 'alt' => '', + 'none' => '', + 'date' => '', ); // Find current attachment post data. @@ -1301,11 +1305,23 @@ public static function get_query_params( $options, $for_filter = false, $layout_ $images[ $k ]['title'] = isset( $img_meta[ $options['images_titles_source'] ] ) ? $img_meta[ $options['images_titles_source'] ] : ''; } + // image title. + $images[ $k ]['image_title'] = isset( $img_meta['title'] ) ? $img_meta['title'] : ''; + // description. if ( 'custom' !== $options['images_descriptions_source'] ) { $images[ $k ]['description'] = isset( $img_meta[ $options['images_descriptions_source'] ] ) ? $img_meta[ $options['images_descriptions_source'] ] : ''; } + // image description. + $images[ $k ]['image_description'] = isset( $img_meta['description'] ) ? $img_meta['description'] : ''; + + // image caption. + $images[ $k ]['image_caption'] = isset( $img_meta['caption'] ) ? $img_meta['caption'] : ''; + + // image alt. + $images[ $k ]['image_alt'] = isset( $img_meta['alt'] ) ? $img_meta['alt'] : ''; + // add published date. $images[ $k ]['published_time'] = get_the_date( 'Y-m-d H:i:s', $attachment ); } @@ -1346,6 +1362,11 @@ public static function get_query_params( $options, $for_filter = false, $layout_ switch ( $custom_order ) { case 'date': case 'title': + case 'description': + case 'image_title': + case 'caption': + case 'alt': + case 'image_description': $sort_tmp = array(); $new_images = array(); $sort_by = 'date'; @@ -1354,6 +1375,26 @@ public static function get_query_params( $options, $for_filter = false, $layout_ $sort_by = 'title'; } + if ( 'description' === $custom_order ) { + $sort_by = 'description'; + } + + if ( 'image_title' === $custom_order ) { + $sort_by = 'image_title'; + } + + if ( 'caption' === $custom_order ) { + $sort_by = 'image_caption'; + } + + if ( 'alt' === $custom_order ) { + $sort_by = 'image_alt'; + } + + if ( 'image_description' === $custom_order ) { + $sort_by = 'image_description'; + } + foreach ( $images as &$ma ) { $sort_tmp[] = &$ma[ $sort_by ]; }