简体   繁体   English

在WordPress URL中传递查询参数

[英]Passing Query Parameters in WordPress URL

I am successfully using the following code in my theme's functions.php file to pass a variable (page number) from a URL (in my case, this is after a mysql query which yields several hundred results): 我已成功在主题的functions.php文件中使用以下代码从URL传递变量(页码)(在我的情况下,这是在mysql查询后产生数百个结果):

function add_query_vars_filter( $vars ){
  $vars[] = "myvar";
  return $vars;
}
add_filter( 'query_vars', 'add_query_vars_filter' );

and then the following to use the variable: 然后使用以下变量:

global $wp_query;
if (isset($wp_query->query_vars['myvar']))
{
$myvar= urldecode($wp_query->query_vars['myvar']);
}

As a beginner, my question is: how do I edit each of these blocks of code to create and use multiple variables (eg, myvar2, myvar3, etc.)? 作为一个初学者,我的问题是:如何编辑这些代码块中的每一个以创建和使用多个变量(例如,myvar2,myvar3等)? Not only do I need to pass a page number, but I need to pass search parameters from the mysql query which are input by the user via forms). 我不仅需要传递页码,而且还需要传递mysql查询中由用户通过表格输入的搜索参数。 I could experiment (as I just did), but for a beginner, messing around with my theme's function.php file and then having the entire site crash requiring me to edit via file manager is a bit nerve-racking. 我可以进行实验(就像我刚刚做的那样),但是对于初学者来说,搞乱主题的function.php文件,然后使整个站点崩溃,需要我通过文件管理器进行编辑有点令人费解。

<a href="?hello=123&bye=456&x=hi"> link </a>
$hello = $_GET['hello'];
$bye = $_GET['bye'];
$x = $_GET['x'];

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

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