Title: Passing variables using the permalink structure
Last modified: August 19, 2016

---

# Passing variables using the permalink structure

 *  [serdominik](https://wordpress.org/support/users/serdominik/)
 * (@serdominik)
 * [17 years ago](https://wordpress.org/support/topic/passing-variables-using-the-permalink-structure/)
 * how to pass variables by using the get pemalink
 * Example:
 * [http://mysite.it/products.php?id=1&title=Name-title](http://mysite.it/products.php?id=1&title=Name-title)
   
   in [http://mysite.it/products/id/1/Name-Title](http://mysite.it/products/id/1/Name-Title)
 * help me!

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [stvwlf](https://wordpress.org/support/users/stvwlf/)
 * (@stvwlf)
 * [17 years ago](https://wordpress.org/support/topic/passing-variables-using-the-permalink-structure/#post-1085624)
 * >  **Adding GET params to a URL in WordPress with add_query_arg**
   >  I am finding
   > myself using this function a lot now, and I constantly forget the function 
   > name: `add_query_arg();` It allows you to pass in some additional parameters,
   > and a URL, and receive back the URL with the query string params added. For
   > example:
   >     ```
   >     $some_url = "http://simonwheatley.co.uk/?stuff=whatever";
   >     $params = array( 'wp_siteurl' => "http://www.example.com" );
   >     $some_url = add_query_arg( $params, $some_url );
   >     ```
   > 
   > This will result in a url something like this:
   >  `http://domain.com/?stuff=whatever&
   > wp_siteurl=http%3A%2F%2Fwww.example.com` Pretty cool, huh? So now you don’t
   > need to worry about what parameters are already in the URL, you can just hand
   > all that hassle to add_query_arg.
 * > **Using custom URL parameters in WordPress**
   >  [http://www.webopius.com/content/137/using-custom-url-parameters-in-wordpress](http://www.webopius.com/content/137/using-custom-url-parameters-in-wordpress)
   > Sometimes when you are building WordPress sites you need to pass a parameter
   > via the URL like this: [http://www.mysite.com?myvar=222](http://www.mysite.com?myvar=222)
   > The problem is that WordPress is designed to reject any URL query parameters
   > that it doesn’t recognise so your URL parameter will be dropped before you 
   > get a chance to use it. The solution Step 1 We need to tell WordPress about
   > the new parameter(s) we will be sending via the URL. We want WordPress to recognise
   > any url parameter sent in the format ‘[http://www.yoursite.com?myvar=hello&#8217](http://www.yoursite.com?myvar=hello&#8217);
   > in any page on our WordPress site. The easiest way to do this is to create 
   > a WordPress plugin that uses a query filter to tell WordPress about new parameters.
   > Here’s the plugin code:
   >     ```
   >     <?php
   >     /* Plugin Name: Parameter
   >     Plugin URI: http://webopius.com/
   >     Description: A plugin to allow parameters to be passed in the URL and recognized by WordPress
   >     Author: Adam Boyse
   >     Version: 1.0
   >     Author URI: http://www.webopius.com/
   >     */
   >     add_filter('query_vars', 'parameter_queryvars' );
   > 
   >     function parameter_queryvars( $qvars )
   >     {
   >     $qvars[] = ' myvar';
   >     return $qvars;
   >     }
   >     ?>
   >     ```
   > 
   > The plugin is configured to add one new URL parameter name ‘myvar’ to WordPress.
   > Just copy the above code to a new .php file which you then copy to the plugins
   > directory of your WordPress install. You then need to activate the new plugin
   > from within your WordPress admin screens.
   > Step 2.
   >  Now from any WordPress page (e.g. Theme page) or standalone page that
   > is WordPress aware you can use your variable like this: global $wp_query;
   >     ```
   >     if (isset($wp_query->query_vars['myvar']))
   >     {
   >     print $wp_query->query_vars['myvar'];
   >     }
   >     ```
   > 
 *  Thread Starter [serdominik](https://wordpress.org/support/users/serdominik/)
 * (@serdominik)
 * [17 years ago](https://wordpress.org/support/topic/passing-variables-using-the-permalink-structure/#post-1085638)
 * Thank you for having responded
    but I’m trying to pass variables using the structures
   permalink
 * would:
 * [http://mysite.it/mypage/myvar/Hello-this-is-value-vars](http://mysite.it/mypage/myvar/Hello-this-is-value-vars)
 * that’s my problem?
 *  [orbitkiller](https://wordpress.org/support/users/orbitkiller/)
 * (@orbitkiller)
 * [16 years, 5 months ago](https://wordpress.org/support/topic/passing-variables-using-the-permalink-structure/#post-1085862)
 * Thanks!
    Your answer helped me a lot! 😉

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Passing variables using the permalink structure’ is closed to new replies.

## Tags

 * [get](https://wordpress.org/support/topic-tag/get/)
 * [permalink](https://wordpress.org/support/topic-tag/permalink/)
 * [variables](https://wordpress.org/support/topic-tag/variables/)

 * 3 replies
 * 3 participants
 * Last reply from: [orbitkiller](https://wordpress.org/support/users/orbitkiller/)
 * Last activity: [16 years, 5 months ago](https://wordpress.org/support/topic/passing-variables-using-the-permalink-structure/#post-1085862)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
