Title: $wp_query-&gt;query_vars in query
Last modified: March 1, 2017

---

# $wp_query->query_vars in query

 *  Resolved [mbruxelle](https://wordpress.org/support/users/mbruxelle/)
 * (@mbruxelle)
 * [9 years, 2 months ago](https://wordpress.org/support/topic/wp_query-query_vars-in-query/)
 * Hi
 * I’m trying to use add_rewrite_rule to have a better URL when showing a gallery
   based on tags.
    I don’t want something like mysite.com/taggallery/?photo_id=5
   but mysite.com/anotherdirectory/5 for instance To that purpose i’ve added this
   in my function.php file :
 *     ```
       function custom_rewrite_tag() {
       add_rewrite_tag('%photo_id%', '([^&]+)');
       }
       add_action('init', 'custom_rewrite_tag', 10, 0);
   
       function custom_rewrite_rule() {
       add_rewrite_rule('^taggallery/([^/]*)/?','index.php?page_id=2382&photo_id=$matches[1]','top');
         }
       add_action('init', 'custom_rewrite_rule', 10, 0);
       ```
   
 * And in the ID=2382 page, I’m using the shorcode with tax query :
 * tax_query=”array ( 0 => array ( ‘taxonomy’ => ‘attachment_tag’, ‘field’ => ‘id’,‘
   terms’ => array( {+request:photo_id+} ), ‘include_children’ => false ) )”
 * The problem is that “+request:photo_id” is empty.
 * Actually, even the php variable $_GET[‘photo_id’] is empty
    photo_id value is
   actually stored in $wp_query->query_vars[‘photo_id’]
 * So I’m wondering if I can use this $wp_query->query_vars[‘photo_id’] variable
   inside the tax_query ?
 * Thanks!

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

 *  Plugin Author [David Lingren](https://wordpress.org/support/users/dglingren/)
 * (@dglingren)
 * [9 years, 2 months ago](https://wordpress.org/support/topic/wp_query-query_vars-in-query/#post-8867361)
 * Thanks for an interesting question. I was able to make all of the `$wp_query-
   >query_vars` elements available for the MLA shortcodes by adding a new custom
   substitution parameter prefix to one of the MLA example plugins. With the example
   plugin installed and activated you can access your value as `+wp_query_vars:photo_id
   +`.
 * I have uploaded a new MLA Development Version dated 20170302 that contains the
   updated MLA Substitution Parameter Hooks Example plugin. To get the Development
   Version, follow the instructions in this earlier topic:
 * [Shortcode not working in (special) widget](https://wordpress.org/support/topic/shortcode-not-working-in-special-widget/?replies=3#post-7753687)
 * Once the Development Version is installed, navigate to the Settings/Media library
   Assistant Documentation tab and click the “Example Plugins” button. Type “substitution”
   in the text box and click “Search Plugins” to filter the table.
    You are looking
   for “MLA Substitution Parameter Hooks Example” plugin. Find that plugin and hover
   over the title in the left-most column. Click the “Install” (or “Update”) rollover
   action, then go to the WordPress Plugins/Installed Plugins submenu and activate
   the example plugin as you would any other plugin.
 * It would be great if you can install the Development Version and updated example
   plugin and let me know how it works for you. Thanks for inspiring an MLA enhancement.
 *  Thread Starter [mbruxelle](https://wordpress.org/support/users/mbruxelle/)
 * (@mbruxelle)
 * [9 years, 2 months ago](https://wordpress.org/support/topic/wp_query-query_vars-in-query/#post-8870637)
 * Hi David,
 * Thanks for your reply.
    I followed your instructions and now the code returns
   this error :
 * ERROR: Invalid mla_gallery tax_query = ‘array ( 0 => array ( \’taxonomy\’ => \’
   attachment_tag\’, \’field\’ => \’id\’, \’terms\’ => array( [+wp_query_vars:photo_id
   +] ), \’include_children\’ => false ) )’
 * Best
    Marc
 *  Plugin Author [David Lingren](https://wordpress.org/support/users/dglingren/)
 * (@dglingren)
 * [9 years, 2 months ago](https://wordpress.org/support/topic/wp_query-query_vars-in-query/#post-8871330)
 * Thanks for your update. You have fallen victim to the quirks of WordPress shortcode
   parsing. You can find more information in the “Entering Long/Complex Shortcodes”
   section of the Settings/Media Library Assistant Documentation tab.
 * You will have better results if you use the “enclosing shortcode” syntax, e.g.:
 *     ```
       [mla_gallery]
       tax_query="
            array(
                array(
                    'taxonomy' => 'attachment_category',
                    'field' => 'id',
                    'terms' => array(11, 12)
                )
            )"
       post_mime_type=image/png link=file
       [/mla_gallery] 
       ```
   
 * Read through the Documentation’s tips, give it a try and let me know if it solves
   your problem.
 *  Plugin Author [David Lingren](https://wordpress.org/support/users/dglingren/)
 * (@dglingren)
 * [9 years ago](https://wordpress.org/support/topic/wp_query-query_vars-in-query/#post-9063448)
 * It has been seven weeks since the last post in this topic. I hope you found the
   enclosing syntax to be a solution for your problem.
 * I am marking this topic resolved, but please update it if you have problems or
   further questions regarding the above suggestions.

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

The topic ‘$wp_query->query_vars in query’ 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/)

 * 4 replies
 * 2 participants
 * Last reply from: [David Lingren](https://wordpress.org/support/users/dglingren/)
 * Last activity: [9 years ago](https://wordpress.org/support/topic/wp_query-query_vars-in-query/#post-9063448)
 * Status: resolved