• Resolved amart41

    (@amart41)


    when sorting images in a gallery using orderby=”rand” I have noticed it’s not actually random at all… it’s just the same order as if I use order=”desc”.

    I am using this plugin along with Photonic Gallery to make a three pane slideshow in the header of my site, which pulls images from a particular category so they can be easily uploaded and updated by a less savvy user.

    I’d like it to be completely random so that every time you refresh the page the slide shows don’t always start on the same image and go in the same order. I would think that using the orderby=”rand parameter in the short code would accomplish this but it doesn’t seem to be, any help would be greatly appreciated.

    http://wordpress.org/extend/plugins/media-library-assistant/

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author David Lingren

    (@dglingren)

    Thanks for this question and for your interest in the plugin. I have just run some tests with version 1.14 and orderby=rand works on my test system; everytime I refresh the page my gallery appears in a different order.

    It sounds like your orderby parameter is not having an effect. Make sure you are coding orderby=rand and NOT order=rand. If you have a test system you can try adding the mla_debug=true parameter had having a look through the debugging output it generates (don’t do it on a public site; it’s ugly!). You should see something like:

    mla_debug request = 'SELECT mladev_posts.* FROM mladev_posts WHERE 1=1 AND (mladev_posts.post_mime_type LIKE \'image/%\') AND mladev_posts.post_type = \'attachment\' AND (mladev_posts.post_status = \'inherit\') AND mladev_posts.post_parent > 0 ORDER BY RAND() ASC '

    The “ORDER BY RAND()” clause is the key. If you don’t see that something is wrong with your shortcode parameters.

    If the above tips don’t solve your problem, please add a comment to this post with the complete [mla_gallery] shortcode you are using and the debug output, if you have it. I’ll try some more testing. I don’t think the Photonic Gallery makes any difference in this case.

    Let me know what you find out!

    Thread Starter amart41

    (@amart41)

    Ok so I’ve gotten some interesting results. For one I couldn’t get any debug out put with the slideshow on so I removed that. I was hopeful that removing that might fix the random problem but unfortunately it didn’t.

    Once I got the debug output it was quite long. Not sure what to make of it all but I did notice that in one of the outputs the orderby line was ORDER BY RAND() DESC.

    Is it possible that using the do_shortcode() function is having an adverse effect because that is how I’m implementing it in my theme outside of the post.

    this is my code:
    echo do_shortcode(‘[mla_gallery mla_debug=\’true\’ attachment_category=\’home-banner-images\’ type=\’default\’ style=\’no-strip\’ fx=\’fade\’ slideshow_height=\’267\’ columns=\’3\’ thumb_width=\’75\’ thumb_height=\’75\’ thumbnail_size=\’thumbnail\’ slide_size=\’thumbnail\’ timeout=\’5000\’ speed=\’1000\’ orderby=\’rand\’ ]’);

    and this is the debug output:

    mla_debug WHERE filter = ‘ AND ( wp_term_relationships.term_taxonomy_id IN (7) ) AND (wp_posts.post_mime_type LIKE \’image/%\’) AND wp_posts.post_type = \’attachment\’ AND ((wp_posts.post_status = \’inherit\’) OR (wp_posts.post_status = \’inherit\’ AND (p2.post_status = \’inherit\’)))’

    mla_debug modified WHERE filter = ‘ AND ( wp_term_relationships.term_taxonomy_id IN (7) ) AND (wp_posts.post_mime_type LIKE \’image/%\’) AND wp_posts.post_type = \’attachment\’ AND ((wp_posts.post_status = \’inherit\’) OR (wp_posts.post_status = \’inherit\’ AND (p2.post_status = \’inherit\’)))’

    mla_debug query = array ( ‘attachment_category’ => ‘home-banner-images’, ‘orderby’ => ‘rand’, ‘post_type’ => ‘attachment’, ‘post_status’ => ‘inherit’, ‘post_mime_type’ => ‘image’, ‘nopaging’ => true, ‘ignore_sticky_posts’ => true, ‘no_found_rows’ => true, )
    mla_debug request = ‘SELECT wp_posts.* FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) LEFT JOIN wp_posts AS p2 ON (wp_posts.post_parent = p2.ID) WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (7) ) AND (wp_posts.post_mime_type LIKE \’image/%\’) AND wp_posts.post_type = \’attachment\’ AND ((wp_posts.post_status = \’inherit\’) OR (wp_posts.post_status = \’inherit\’ AND (p2.post_status = \’inherit\’))) GROUP BY wp_posts.ID ORDER BY RAND() DESC ‘

    mla_debug query_vars = array ( ‘attachment_category’ => ‘home-banner-images’, ‘orderby’ => ‘rand’, ‘post_type’ => ‘attachment’, ‘post_status’ => ‘inherit’, ‘post_mime_type’ => ‘image’, ‘nopaging’ => true, ‘ignore_sticky_posts’ => true, ‘no_found_rows’ => true, ‘error’ => ”, ‘m’ => 0, ‘p’ => 0, ‘post_parent’ => ”, ‘subpost’ => ”, ‘subpost_id’ => ”, ‘attachment’ => ”, ‘attachment_id’ => 0, ‘name’ => ”, ‘static’ => ”, ‘pagename’ => ”, ‘page_id’ => 0, ‘second’ => ”, ‘minute’ => ”, ‘hour’ => ”, ‘day’ => 0, ‘monthnum’ => 0, ‘year’ => 0, ‘w’ => 0, ‘category_name’ => ”, ‘tag’ => ”, ‘cat’ => ”, ‘tag_id’ => ”, ‘author_name’ => ”, ‘feed’ => ”, ‘tb’ => ”, ‘paged’ => 0, ‘comments_popup’ => ”, ‘meta_key’ => ”, ‘meta_value’ => ”, ‘preview’ => ”, ‘s’ => ”, ‘sentence’ => ”, ‘fields’ => ”, ‘menu_order’ => ”, ‘category__in’ => array ( ), ‘category__not_in’ => array ( ), ‘category__and’ => array ( ), ‘post__in’ => array ( ), ‘post__not_in’ => array ( ), ‘tag__in’ => array ( ), ‘tag__not_in’ => array ( ), ‘tag__and’ => array ( ), ‘tag_slug__in’ => array ( ), ‘tag_slug__and’ => array ( ), ‘suppress_filters’ => false, ‘cache_results’ => false, ‘update_post_term_cache’ => true, ‘update_post_meta_cache’ => true, ‘posts_per_page’ => 10, ‘comments_per_page’ => ’50’, ‘taxonomy’ => ‘attachment_category’, ‘term’ => ‘home-banner-images’, ‘order’ => ‘DESC’, )

    Plugin Author David Lingren

    (@dglingren)

    Thank you! You’re right – you can’t get the debug output when you use Photonic (I should have thought of that).

    The query specs and the debug output are very helpful. The testing I did so far did not involve filtering by attachment_category. It’s possible that has some effect, and I will do additional testing that more closely replicates all of the parameters you’re using in your query. I don’t think the do_shortcode method has any effect on the outcome.

    I will keep you posted on my progress. Thanks for your patience.

    Plugin Author David Lingren

    (@dglingren)

    I’ve done more research and it turns out that the gallery image objects are passed from MLA to Photonic in a way that precludes a random order. I have started a topic on the Photonic support forum asking for help with this issue:

    Support for the jQuery Cycle Plugin “random’ Option

    I will post an update here if I get a response and/or find a different way to handle random order. Thanks again for your patience and for your understanding.

    Thread Starter amart41

    (@amart41)

    Awesome thanks for your help so far.

    Plugin Author David Lingren

    (@dglingren)

    I haven’t had any response to the topic I posted on the Photonic support forum, but I have added a new feature to [mla_gallery] which will solve your problem.

    The next Media Library Assistant release will include a new way to separating the data selection and format/display parts of gallery production, so you can use [mla_gallery] to select the attachments you want and then hand off a list of their IDs to any other shortcode that accepts a list of IDs as input. I’ve tested this with the Photonic Gallery and it works, giving you the random order you’re looking for.

    The new version (1.30) will be out in a week or so. Let me know if it helps or if you have problems or questions about it.

    Plugin Author David Lingren

    (@dglingren)

    I’ve just released version 1.30, which includes the new mla_alt_shortcode parameter that should resolve this issue. For example, to get a random order you can code something like:

    [mla_gallery ids="272,268,267,266" orderby=rand mla_alt_shortcode=gallery type=default style=strip-below slideshow_height=320 slide_size=medium]

    You can replace the ids= parameter with whatever data selection parameters your application requires. The mla_alt_shortcode=gallery parameter will direct the list of gallery item to the standard WordPress [gallery] shortcode. The type=default parameter will activate the Photonic plugin and the remaining parameters will be passed along to Photonic for its own use in formatting the gallery.

    I’m going to mark this issue resolved; if you have any trouble with the new version, let me know. Thanks for your patience!

    Thread Starter amart41

    (@amart41)

    Sorry it’s taken so long for me to reply to this Dave, we’ve been in a holding pattern with this client and I only just had the opportunity to try this out. Unfortunately I’m still not getting a random order. I tried putting in specific id #’s rather than pulling the whole category I want but that didn’t work either. Here’s my code again:

    [mla_gallery attachment_category=home-banner-images orderby=rand mla_alt_shortcode=gallery type=default style=no-strip fx=fade slideshow_height=267 columns=3 thumb_width=75 thumb_height=75 thumbnail_size=thumbnail slide_size=thumbnail timeout=5000 speed=1000]

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your update – sorry you are still having trouble with this. I just ran a test with the following code:

    [mla_gallery ids="272,268,267,266" orderby=rand mla_alt_shortcode=gallery type=default style=no-strip fx=fade slideshow_height=267 columns=3 thumb_width=75 thumb_height=75 thumbnail_size=thumbnail slide_size=thumbnail timeout=5000 speed=1000]

    Of course, it works flawlessly on my system. I get the four images in a different order every time I refresh the page.

    If your site is accessible on the Internet, could you send me a link to the offending page? I’d like to see the HTML source code generated by the gallery.

    Also, you could try using order=ID order=DESC and a list of id numbers; does the gallery order match the order in the list you supply? In other words, is the ordering issue specific to “rand” or is sorting ignored entirely?

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Orderby not working’ is closed to new replies.