tags:

views:

36

answers:

1

Let us say that I have a form to search by multiple tags in wordpress.

<input type="checkbox" name="my_tags[]" value="tag1" />
<input type="checkbox" name="my_tags[]" value="tag2" />

I want to make it so that when my plugin sees that my_tags[] is set, it rewrites the request to say

mysite.com/?tag=tag1+tag2

I know to use add_query_arg to put in the tag, and to use the query_vars filters to allow my arguments to be sent, but what do i hook into to get the arguments that were sent after the request, but before wp parses the request?

A: 

My understanding is that you wouldn't really be 'replacing' the query in the current request, but rather forming a new request URI and redirecting the client with wp_redirect() with the default 302 Found status code. Something like:

wp_redirect( add_query_arg( array( 'tag' => implode( ' ', $_REQUEST['my tags'] ) ), bloginfo('url') ), 302);

This sort of housecleaning has to happen before headers are sent, obviously. A logical place to hook it in through the Plugin API would be the parse_request or send_headers actions. I mean, all you're doing here is parsing a request and sending headers. :P

I know nearly nothing about doing this with a server rewrite in the .htaccess file, though, so maybe you might explore that as well.

cowbellemoo
except that you ought to be using get_bloginfo() instead of bloginfo(), I agree.
Joseph Carrington