• Resolved kkjelgaard

    (@kkjelgaard)


    I would like to to order a gallery by the attachment category slug. I’m building a portfolio gallery with the ability to jump between categories of images. All categories are the child of the attachment category work. Here’s the gallery shortcode I have now:

    A navigation menu:

    [mla_term_list \
    taxonomy=attachment_category \
    parent=3 \
    mla_style=none \
    mla_link_attributes='data-gallery-count={+count+} data-gallery-slug={+slug+}' \
    mla_rollover_text='\n' \
    ]

    And a Gallery shortcode:

    [mla_gallery \
    itemtag="div" \
    attachment_category=work \
    orderby=attachment_category \
    tax_include_children=true \
    mla_style=none \
    ]

    The term list displays categories in alphabetical order, whereas the gallery displays the images in descending alphabetical order. Orderby doesn’t seem to support attachment_category as an option. If I can’t get the shortcode to do this, I suppose I can use javascript to sort by the attachment category slug. Any suggestions?

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

    (@dglingren)

    Thanks for your question. Thanks as well for including the text of your shortcodes; very helpful.

    The [mla_gallery orderby=] parameter simply passes the parameter value on to the WordPress WP_Query function; here’s a link to more information:

    WP_Query Order & Orderby Parameters

    As you can see there, taxonomy terms are not one of the available options. One reason for this is that an item can be assigned to multiple terms, and in general it’s not possible to decide which term should be used for the sort order.

    The closest solution I can think of would be to create a custom field containing the term slug you want to sort on and then sorting on the value of that custom field. If that’s helpful I can give you more specific guidance.

    I regret the news is not better, but I am marking this topic resolved because your question has been answered. If you have any further questions or want to pursue the custom field alternative, post an update here and I will give you what help I can. Thanks for your interest in the plugin.

    Thread Starter kkjelgaard

    (@kkjelgaard)

    Totally understandable that sorting by an array of multiple possible values does not make sense. I am using a matching custom field as a workaround for now. I may need to come up with a custom shortcode that does the array manipulation to create something that is usable by the client.

    If it’s possible somehow through a custom WP_Query, an acceptable workaround could be to just use the first taxonomy in the array of child taxonomies for each item.

    Plugin Author David Lingren

    (@dglingren)

    Thanks for understanding and for giving the custom field alternative a try.

    As I wrote earlier, WP_Query (with or without MLA) is not able to accomplish your goal. The custom shortcode idea is a good one. You could do the initial data selection in the custom shortcode, find the term assignments, sort the results and then pass the IDs in the order you want them to MLA (with do_shortcode()) to format the gallery. You could also use MLA for the initial selection and use the mla_alt_shortcode parameter to pass the IDs to your shortcode for the term assignment and sorting step.

    I am leaving this topic resolved, but please update it if you need further help with the custom shortcode idea.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Order gallery by attachment category’s slug’ is closed to new replies.