$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!
- The topic ‘$wp_query->query_vars in query’ is closed to new replies.