• Resolved tosca30

    (@tosca30)


    I would like to order the gallery using a custom field, but I cannot find the right format to do so. Currently, my code is:
    do_shortcode(sprintf('[mla_gallery s="%s" tax_query="%s" my_filter="term gallery" paged=current meta_key="pic_ref" orderby="meta_value" order="DESC"]', $wp_query->query_vars['s'], $my_tax_query));
    but it doesn’t work.

    In fact, this doesn’t show any result since I added the
    meta_key="pic_ref" orderby="meta_value" order="DESC" bit.

    Could you help to find the right syntax?
    Thanks a lot.

    https://www.ads-software.com/plugins/media-library-assistant/

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

    (@dglingren)

    I have just run some tests along the lines of your example. Assuming that your $wp_query->query_vars['s'], $my_tax_query values are valid it looks like your syntax is correct. In my tests I get a properly filtered and sorted gallery. Here is my test case:

    [mla_gallery s="raft" paged=current tax_query="array(array('taxonomy' => 'category', 'field' => 'slug', 'terms' => 'general' ))" mla_caption="{+caption+}<br>{+custom:Archive Date+}" meta_key="Archive Date" orderby="meta_value" order="DESC" mla_debug=true]

    One thing you should know is that any item that does not have a value for the custom field (“pic_ref” in your case) will not be included in the gallery because the SQL JOIN clause will eliminate them. So, you should make sure that all of your items have a non-NULL value for the custom field you are sorting on.

    Here are some things you can try:

    1. Add the mla_debug=true parameter to the shortcode. It will display a lot of information that would help reveal what is happening. Capture the data and e-mail it to me so I can have a closer look.
    2. Remove the s="%s" and tax_query="%s" parameters, add post_parent=all and test with just the custom field sort. Do you get the images you expect?

    Verify your custom field contents, try those two experiments and let me know the results. I am confident we can make this work for you.

    Thread Starter tosca30

    (@tosca30)

    I’m away from home for a few days, and testing is not very easy…
    At the moment, everything seems to work as it should though I’ve not changed anything yet!
    I will test more thoroughly next week, when I’ll have access to my development system, and give you a definitive answer.

    Thanks for having confirmed the syntax.

    Thread Starter tosca30

    (@tosca30)

    I’m afraid I can’t reproduce this issue.
    Consider it being solved.

    Sorry for the disturbance.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Ordering on a custom field’ is closed to new replies.