开发者

How to change the wordpress header request

开发者 https://www.devze.com 2022-12-26 09:11 出处:网络
Let us say that I have a form to search by multiple tags in wordpress. <input type=\"checkbox\" name=\"my_tags[]\" value=\"tag1\" />

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 afte开发者_如何学运维r the request, but before wp parses the request?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消