简体   繁体   English

从当前网址中删除特定查询“&cat = -22”-PHP-Wordpress Relevanssi搜索结果

[英]Remove specific query “&cat=-22” from current url - php - wordpress relevanssi search results

I have added a button to my search results to exclude a particular category from the results (simply adds &cat=-22 to the current url). 我在搜索结果中添加了一个按钮,以从结果中排除特定类别(只需将&cat=-22添加到当前网址中)。

I am trying to figure out a way to add another button to "remove" the query from the current url (ie http://host/?s=test&cat=-22 will end up being http://host/?s=test ). 我试图找出一种方法来添加另一个按钮来“删除”当前网址中的查询(即http://host/?s=test&cat=-22最终将成为http://host/?s=test )。

If possible it needs to only remove the text specified as it is possible the query may not always be at the end of the url, ie can be 如果可能的话,只需要删除指定的文本,因为查询可能并不总是在URL的末尾,即可以是

http://host/?s=test&cat=-22&orderby=post_modified&order=desc

or 要么

http://host/?s=test&orderby=post_modified&order=desc&cat=-22

I have tried to adapt several methods listed here and elsewhere but end up removing only the 'cat' which is not great if for some reason the user clicks the link when searching a specific category, ie 我试图适应这里和其他地方列出的几种方法,但最终仅删除了“ cat”,如果用户出于某种原因在搜索特定类别时单击链接,则该猫就不太好了,即

http://host/?s=test&orderby=post_modified&order=desc&cat=2

becomes 变成

http://host/?s=test&orderby=post_modified&order=desc

when link is clicked. 单击链接时。

Hope that makes sense! 希望有道理!

Any help with this would be very much appreciated! 任何帮助,将不胜感激!

Mike 麦克风

I wrote this today, I think you may be able to adapt it to what you need. 我今天写了这篇文章,我想您也许可以将其适应您的需求。

What it does is accept $_SERVER['query_string'] as the $string, then just type in the $key and $value you want to remove. 它的作用是接受$ _SERVER ['query_string']作为$ string,然后只需键入要删除的$ key和$ value。

public function removeGetVariable($string, $key)
{

    parse_str($string, $variables);

    unset($variables[$key]);

    return http_build_query($variables);

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM