Title: Using $_get inside a shortcode
Last modified: August 20, 2016

---

# Using $_get inside a shortcode

 *  Resolved [gregounours](https://wordpress.org/support/users/gregounours/)
 * (@gregounours)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/using-_get-inside-a-shortcode/)
 * I am new to this so bear with me 🙂
 * I am trying to use a url variable inside a shortcode on a page.
    Let’s say my
   url is [http://tralala.com/pouet/?youpi=meuh](http://tralala.com/pouet/?youpi=meuh)
 * I am using tablepress and would like to have the output of the folowing shortcode
   displayed: [table id=x filter=”meuh” show_columns=”2,4,6″/]
 * I have looked around a bit and this seemed like the way to go:
    <?php $myvar 
   = $_GET[‘youpi’]; echo do_shortcode(“[table id=x filter=’$myvar’ show_columns
   =’6′); ?>
 * Unfortunately that code display the below text on the page:
 * $myvar = $_GET[‘youpi’];
    do_shortcode(“[table id=7 filter=’$myvar’ show_columns
   =’4,5,6′); ?>
 * It does not make sense to me at all why it would just display that.
 * Thanks in advance for your enlightening answers

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

 *  [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/using-_get-inside-a-shortcode/#post-3245539)
 * Hi,
 * thanks for your question.
 * The best approach for this would be to create a new Shortcode that gets the $
   _GET parameter and passes that on to the TablePress template tag:
 *     ```
       add_shortcode( 'table_filter', 'tablepress_filter_shortcode' );
       function tablepress_filter_shortcode( $attributes, $content ) {
       	if ( ! empty( $_GET['table_filter'] ) ) {
       		$filter_term = $_GET['table_filter'];
       		$filter_term = preg_replace( '#[^a-z0-9]#i', '', $filter_term ); // only allow characters a-z, A-Z, and 0-9 in filter term
       		$attributes['filter'] = $filter_term;
       	}
       	return tablepress_get_table( $attributes );
       }
       ```
   
 * Just add that as a small Extension by installing and activating [https://github.com/downloads/TobiasBg/TablePress-Extensions/tablepress-shortcode-filter-get-parameter.zip](https://github.com/downloads/TobiasBg/TablePress-Extensions/tablepress-shortcode-filter-get-parameter.zip)
   as a regular WordPress plugin.
    After that, you would use this Shortcode:
 *     ```
       [table_filter id=x show_columns="2,4,6"/]
       ```
   
 * The filter term is added automatically from the “table_filter” argument in the
   URL, i.e. from `$_GET['table_filter']`.
 * Regards,
    Tobias
 *  Thread Starter [gregounours](https://wordpress.org/support/users/gregounours/)
 * (@gregounours)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/using-_get-inside-a-shortcode/#post-3245540)
 * Awesome !!!
 *  [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/using-_get-inside-a-shortcode/#post-3245551)
 * Hi,
 * no problem, you are very welcome! 🙂
 * Best wishes,
    Tobias

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

The topic ‘Using $_get inside a shortcode’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * Last activity: [13 years, 5 months ago](https://wordpress.org/support/topic/using-_get-inside-a-shortcode/#post-3245551)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
