Media Library Assistant
[resolved] Gallery shortcode question (4 posts)

  1. Alexander S. Kunz
    Posted 2 years ago #

    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.


  2. David Lingren
    Plugin Author

    Posted 2 years ago #

    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!


  3. Alexander S. Kunz
    Posted 2 years ago #

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

  4. Alexander S. Kunz
    Posted 2 years ago #


Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Media Library Assistant
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic