Title: passing custom variable through permalink
Last modified: August 19, 2016

---

# passing custom variable through permalink

 *  [windsurfer](https://wordpress.org/support/users/windsurfer/)
 * (@windsurfer)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/passing-custom-variable-through-permalink/)
 * Hi,
 * I’m developing a site and I need to pass variable through permalink.
 * 1. I have a page like [http://www.example.com/category_name/post_name](http://www.example.com/category_name/post_name)
 * and I need to make something like
 * 2. [http://www.example.com/category_name/post_name/specs](http://www.example.com/category_name/post_name/specs)
 * 2nd should show the same post like 1st but I will have variable e.g. $specs=specs
   and I will know what part on the post page to show.
 * How can I do it ?
 * Thanks

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

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/passing-custom-variable-through-permalink/#post-1701372)
 * `<a href="<?php echo get_permalink(); ?>/<?php echo $specs;?>`“>Foobar`
 * [http://codex.wordpress.org/Function_Reference/get_permalink](http://codex.wordpress.org/Function_Reference/get_permalink)
 *  Thread Starter [windsurfer](https://wordpress.org/support/users/windsurfer/)
 * (@windsurfer)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/passing-custom-variable-through-permalink/#post-1701696)
 * Hi,
 * thank you for your help but I know how to make link to the page. Problem is that
   when I go to [http://www.example.com/category_name/post_name/specs](http://www.example.com/category_name/post_name/specs)
   I got 404 error. I made plugin like this:
 *     ```
       function add_query_vars($aVars) {
           global $wp_query;
           $aVars[] = "specs";    // represents the name of the product category as shown in the URL
   
           return $aVars;
       }
       //// hook add_query_vars function into query_vars
       add_filter('query_vars', 'add_query_vars');
   
       function add_rewrite_rules($aRules) {
           $aNewRules = array('(.+)/(.+)/specs' => 'index.php?name=$matches[2]&specs=specs');
           $aRules = $aNewRules + $aRules;
   
           return $aRules;
       }
       add_filter('rewrite_rules_array', 'add_rewrite_rules');
       ```
   
 * But when I go to [http://www.example.com/category_name/post_name/specs](http://www.example.com/category_name/post_name/specs)
   I’m redirected to [http://www.example.com/category_name/post_name](http://www.example.com/category_name/post_name)
   and I can’t find $specs in $wp_query.
 * Thanks for help

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

The topic ‘passing custom variable through permalink’ is closed to new replies.

## Tags

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

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 2 replies
 * 2 participants
 * Last reply from: [windsurfer](https://wordpress.org/support/users/windsurfer/)
 * Last activity: [15 years, 6 months ago](https://wordpress.org/support/topic/passing-custom-variable-through-permalink/#post-1701696)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
