Support » Plugin: Media Library Assistant » Gallery shortcode question

  • Hello David,

    I want to compile a list of my top 10 photos from 2012 like so:

    [mla_gallery attachment_tag=”top10,2012″]

    However, also photos that are NOT tagged “2012” are shown in the gallery.

    It appears that passing a number of tags to the gallery shortcode connects them with an OR statement, showing items that contain either one or the other tag.

    Is there a way to connect tags with an AND statement, like, show only those attachments that contain BOTH tags?

    Thank you.

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


    Yes! Here’s the relevent part of the [mla_gallery] documentation from the Settings page:

    More complex queries can be specified by using “tax_query”, e.g.:

    * [mla_gallery tax_query="array(array('taxonomy' => 'attachment_tag','field' => 'slug','terms' => 'artisan'))"]
    * [mla_gallery tax_query="array(array('taxonomy' => 'attachment_category','field' => 'id','terms' => array(11, 12)))" post_parent=current post_mime_type='']

    The first example is equivalent to the simple query “attachment_tag=artisan”. The second example matches items of all MIME types, attached to the current post, having an attachment_category ID of 11 or 12.

    When embedding the shortcode in the body of a post, be very careful when coding the tax_query; it must be a valid PHP array specification. In particular, code the query on one line; splitting it across lines can insert HTML tags and corrupt your query.

    Remember to use “post_parent=current” if you want to restrict your query to items attached to the current post.

    You can find more information at:


    For your application, I believe the appropriate query would be:

    [mla_gallery tax_query="array(array('taxonomy' => 'attachment_tag','field' => 'slug','terms' => array('top10', '2012'), 'operator' => 'AND' ))"]

    Let me know if you have any problems with this query; remember, put it on one line in your post!

    Thanks for the question and for using the plugin!


    Thanks a lot, David! It works, and I will continue to shamelessly copy this code to wherever I need it. 😉


Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Gallery shortcode question’ is closed to new replies.