简体   繁体   中英

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):

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.)? 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). 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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