Title: MLA Gallery Shortcode
Last modified: May 19, 2020

---

# MLA Gallery Shortcode

 *  Resolved [vam2017](https://wordpress.org/support/users/vam2017/)
 * (@vam2017)
 * [6 years ago](https://wordpress.org/support/topic/mla-gallery-shortcode/)
 * Hi. Thanks so much for such a good plugin. I was looking for different options.
   This plugin is the best.
    I have a question. I need to make a page with a gallery
   and a tag cloud. Here is the code:
 *     ```
       [mla_tag_cloud]
       taxonomy=attachment_tag 
       mla_link_href="[+page_url+]?current_id={+term_id+}"
       number=0 smallest=12 largest=12 separator=' / '
       [/mla_tag_cloud]
   
       [mla_gallery]
       tax_query= "array ( 0 => array ( 'taxonomy' => 'attachment_tag', 'field' => 'id', 'terms' => array( {+request:current_id+} ) ) )"
       mla_caption="{+image_alt+}" 
       columns=3 posts_per_page=20 size=full link=file 
       mla_link_class="nav-links"
       [/mla_gallery]
   
       [mla_gallery]
       mla_output="paginate_links,prev_next"
       mla_link_class="nav-links"
       tax_query= "array ( 0 => array ( 'taxonomy' => 'attachment_tag', 'field' => 'id', 'terms' => array( {+request:current_id+} ) ) )"
       columns=3 posts_per_page=20 size=full link=file
       [/mla_gallery]
       ```
   
 * Everything works, but there is one problem.
    When I go to the gallery page for
   the first time, I see only a tag cloud, but there is no image gallery itself.
   After clicking on the tag cloud links, everything works fine. How to make the
   gallery visible immediately upon entering the page? I would be grateful for an
   example.
 * Thanks a lot

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Thread Starter [vam2017](https://wordpress.org/support/users/vam2017/)
 * (@vam2017)
 * [6 years ago](https://wordpress.org/support/topic/mla-gallery-shortcode/#post-12859351)
 * I forgot to say
    All images belong to the same Att. Category: mygallery
 *  Plugin Author [David Lingren](https://wordpress.org/support/users/dglingren/)
 * (@dglingren)
 * [6 years ago](https://wordpress.org/support/topic/mla-gallery-shortcode/#post-12861328)
 * Thanks for the positive feedback and for your question. Thanks as well for posting
   the complete source text of your shortcodes; very helpful.
 * For your example, when the page loads without a `current_id=` query attribute
   the `tax_query=` parameters have an empty `terms =` array. This matches no items
   and gives an empty gallery result. The solution is to make the entire `tax_query
   =` value conditional on the presence of the `{+request:current_id+}` substitution
   parameter. When I tested this solution I discovered that the current MLA version
   does not allow empty `tax_query=` values, which I consider to be a defect.
 * I have uploaded a new MLA Development Version dated 20200519 that allows and 
   ignores empty `tax_query=` values. You can find step-by-step instructions for
   using the Development Version in this earlier topic:
 * [PHP Warning on media upload with Polylang](https://wordpress.org/support/topic/php-warning-on-media-upload-with-polylang/#post-9625341)
 * It would be great if you could install the Development Version, update your shortcodes(
   see below) and let me know if you find any problems. Thanks for alerting me to
   this MLA defect.
 * The `[mla_tag_cloud]` shortcode does not need any changes. To make your `tax_query
   =` values conditional you can use a content template as follows:
 *     ```
       [mla_gallery]
       tax_query= "{+template:(array \\( 0 => array \\( 'taxonomy' => 'attachment_tag', 'field' => 'id', 'terms' => array\\( {+request:current_id+} \\) \\) \\))+}"
       post_parent=all
       mla_caption="{+image_alt+}" 
       columns=3 posts_per_page=20 size=full link=file 
       mla_link_class="nav-links"
       [/mla_gallery]
   
       [mla_gallery]
       mla_output="paginate_links,prev_next"
       mla_link_class="nav-links"
       tax_query= "{+template:(array \\( 0 => array \\( 'taxonomy' => 'attachment_tag', 'field' => 'id', 'terms' => array\\( {+request:current_id+} \\) \\) \\))+}"
       post_parent=all
       columns=3 posts_per_page=20 size=full link=file
       [/mla_gallery]
       ```
   
 * In the above example I have enclosed the query value with `{+template:( … )+}`.
   I have also added double backslashes before the parentheses inside the query 
   so they are ignored by the content template processor. Finally, I have added `
   post_parent=all` so all of your items are displayed on the initial page load.
 * You wrote “**_All images belong to the same Att. Category: mygallery_**“. I do
   not see any shortcode parameters reflecting this. You can try replacing the `
   post_parent=all` parameter with `attachment_category=mygallery` to filter the
   initial gallery display by the Att. Category value.
 * I will leave this topic unresolved in case you have problems or further questions
   regarding installing the Development Version and updating your shortcodes. Thanks
   for your interest in the plugin.
 *  Thread Starter [vam2017](https://wordpress.org/support/users/vam2017/)
 * (@vam2017)
 * [6 years ago](https://wordpress.org/support/topic/mla-gallery-shortcode/#post-12862144)
 * Fine. Thank you so much!
    Updated the plugin as you said. Everything is working
   well. Below is the working code:
 *     ```
       [mla_tag_cloud]
       taxonomy=attachment_tag 
       mla_link_href="[+page_url+]?current_id={+term_id+}"
       number=0 smallest=12 largest=12 separator=' / '
       [/mla_tag_cloud]
   
       [mla_gallery] 
       attachment_category=mygallery
       tax_query= "{+template:(array \\( 0 => array \\( 'taxonomy' => 'attachment_tag', 'field' => 'id', 'terms' => array\\( {+request:current_id+} \\) \\) \\))+}"
       post_parent=all
       mla_caption="{+image_alt+}" 
       columns=3 posts_per_page=4 size=full link=file 
       mla_link_class="nav-links"
       [/mla_gallery]
   
       [mla_gallery]
       attachment_category=mygallery
       mla_output="paginate_links,prev_next"
       mla_link_class="nav-links"
       tax_query= "{+template:(array \\( 0 => array \\( 'taxonomy' => 'attachment_tag', 'field' => 'id', 'terms' => array\\( {+request:current_id+} \\) \\) \\))+}"
       post_parent=all
       columns=3 posts_per_page=4 size=full link=file
       [/mla_gallery]
       ```
   
 *  Plugin Author [David Lingren](https://wordpress.org/support/users/dglingren/)
 * (@dglingren)
 * [6 years ago](https://wordpress.org/support/topic/mla-gallery-shortcode/#post-12866509)
 * Thanks for trying the Development Version and confirming that it’s working for
   your application. Thanks as well for posting the updated source text do others
   can see it.
 * The fix will also be part of my next MLA update, which you will get through the
   normal plugin update process.
 * I am marking this topic resolved, but please update it of you have any problems
   or further questions regarding the conditional tax_query.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘MLA Gallery Shortcode’ is closed to new replies.

 * ![](https://ps.w.org/media-library-assistant/assets/icon-256x256.png?rev=973502)
 * [Media Library Assistant](https://wordpress.org/plugins/media-library-assistant/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/media-library-assistant/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/media-library-assistant/)
 * [Active Topics](https://wordpress.org/support/plugin/media-library-assistant/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/media-library-assistant/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/media-library-assistant/reviews/)

## Tags

 * [gallery](https://wordpress.org/support/topic-tag/gallery/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)
 * [tag_cloud](https://wordpress.org/support/topic-tag/tag_cloud/)

 * 4 replies
 * 2 participants
 * Last reply from: [David Lingren](https://wordpress.org/support/users/dglingren/)
 * Last activity: [6 years ago](https://wordpress.org/support/topic/mla-gallery-shortcode/#post-12866509)
 * Status: resolved