Skip to content

Commit

Permalink
added sort by image fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Fellan-91 committed Apr 24, 2024
1 parent 5158f89 commit 24601d6
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 10 deletions.
13 changes: 9 additions & 4 deletions classes/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
),
)
);
Expand Down
53 changes: 47 additions & 6 deletions classes/class-get-portfolio.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 );
}
Expand Down Expand Up @@ -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';
Expand All @@ -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 ];
}
Expand Down

0 comments on commit 24601d6

Please sign in to comment.