Support » Plugin: ACF Photo Gallery Field » Images sortable but not displayed in correct order

  • Hi,

    i just realized that the images are ordered by date added instead of the order you sort them in backend. Is there any way to get them in sorted order?

    Best regards

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Navneil Naicker


    Hi Christian,

    I had a look at the source code again and noticed that the images are being ordered by the order you sort them in the back-end. I’m not sure why your images sorting by date. I hope you are using the latest version of the plugin.

    Additionally you can pass 2 more parameter to the acf_photo_gallery to sort it by the order you sorted in the back-end. See the code below:
    acf_photo_gallery('ACF_FIELD_NAME', $post->ID, 'ASC', 'post__in');

    I have the same problem. I found out that the order of the image-I’s is changed in the get_posts ($args) statement in act_photo_gallery.php
    $args = array( ‘post_type’ => ‘attachment’, ‘posts_per_page’ => -1, ‘post__in’ => $images, ‘order’ => $order, ‘orderby’ => $orderby );

    I also call the function like this:
    $images = acf_photo_gallery(‘foto_gallerij’, $post->ID, ‘ASC’, ‘post__in’);
    and changed:
    function acf_photo_gallery($field = null, $post_id, $order = ‘ASC’, $orderby = ‘post__in’)
    echo $field . ‘<br />’;
    echo $orderby . ‘<br />’ . $order . ‘<br />’;
    $images = get_post_meta($post_id, $field, true); echo $images . ‘<br />’; // 1
    return acf_photo_gallery_make_images($images, $field, $post_id, $order, $orderby);

    The $order & $orderby are passed thru to the last function (…make_images) but are not correctly used by get_posts

    Hoping on a solution… regards, Derk-Jan

    by the way i don’t understand why function get_posts() can be declared multiple times in my WordPress installation (ACF, Jetpack (not activated), MPC-massive (Addons), WPML)

    … by the wayan example, with testcode is on the website

    this is the query:
    SELECT DISTINCT wp_posts.*
    FROM wp_posts JOIN wp_icl_translations wpml_translations
    ON wp_posts.ID = wpml_translations.element_id
    AND wpml_translations.element_type = CONCAT(‘post_’, wp_posts.post_type)
    WHERE 1=1
    AND wp_posts.ID IN (61639,61374,61630,53763,53772,53766,53541,53538,52620,51930,51909,51753,51693,51525,51522,51447,51408,49659,49404,49311,49305,49320,49323,47939,47588,47312,47321,47291,47078,43459,43495,43474,43501,43498,44119,44025,44131,47963,48044,47984,47981,47918,47903,47975)
    AND wp_posts.post_type = ‘attachment’
    AND ((wp_posts.post_status = ‘inherit’))
    AND ( ( ( wpml_translations.language_code = ‘nl’
    OR 0 )
    AND wp_posts.post_type IN (‘post’,’page’,’attachment’,’product’,’product_variation’,’cookielawinfo’,’templatera’ ) )
    OR wp_posts.post_type NOT IN (‘post’,’page’,’attachment’,’product’,’product_variation’,’cookielawinfo’,’templatera’ ) )
    ORDER BY wp_posts.post_modified DESC

    Looks like the arguments in $args are not passed through by wp_parse_args in wp_includes/post.php

    Plugin Author Navneil Naicker


    Thanks @djbdijkstra I’ll be making the necessary changes and will push these changes in next release.

    Thanks, keep me posted if possible!

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.