• Resolved mbruxelle

    (@mbruxelle)


    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

    (@dglingren)

    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

    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

    (@mbruxelle)

    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

    (@dglingren)

    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

    (@dglingren)

    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.